I have a Jenkins pipeline. A stage with build image is as below:
stage('Build image'){
sh 'docker build -t myImage --file $WORKSPACE/build/Dockerfile .'
}
I want to add 'BUILD_NUMBER' jenkins variable to tag the image.
Is the below approach is correct? Or any other way?
stage('Build image'){
sh 'docker build -t myImage:${BUILD_NUMBER} --file $WORKSPACE/build/Dockerfile .'
}
Thanks in advance.
Below worked for me:
stage('Build image'){
sh 'docker build -t myImage:${BUILD_NUMBER} --file $WORKSPACE/build/Dockerfile .'
}
Thanks.
can you try something like this :
sh 'docker build -t myImage:${env.BUILD_NUMBER} --file $WORKSPACE/build/Dockerfile .'
i remove one ':' and also add env before BUILD_NUMBER can be variant according to your jenkins
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.