Skip to content

Commit dd93160

Browse files
committed
fix push stage docker#1
1 parent 981f656 commit dd93160

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Jenkinsfile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,17 @@ pipeline {
4747
}
4848
}
4949

50-
stage('Push') {
51-
agent any
50+
stage('Push to Docker Hub') {
5251
steps {
53-
withCredentials([usernamePassword(credentialsId: 'dockerHub', passwordVariable: 'dockerHubPassword', usernameVariable: 'dockerHubUser')]) {
54-
sh '''
55-
docker login -u ${env.dockerHubUser} -p ${env.dockerHubPassword}
56-
docker image tag ${docker_image}:v1
57-
dockr push ${docker_image}:v1
58-
'''
52+
// Use withCredentials to access Docker Hub credentials
53+
withCredentials([usernamePassword(credentialsId: 'dockerHub', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
54+
script {
55+
// Log in to Docker Hub
56+
sh 'echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin'
57+
sh 'docker build -t ${docker_image}:v1'
58+
// Push the image
59+
sh 'docker push ${docker_image}:v1'
60+
}
5961
}
6062
}
6163
}

0 commit comments

Comments
 (0)