简体   繁体   English

如何使用詹金斯管道参数标记Docker镜像?

[英]How to tag docker image with jenkins pipeline parameter?

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. 我想添加“ BUILD_NUMBER”詹金斯变量来标记图像。

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 我删除了一个':',并在BUILD_NUMBER根据您的詹金斯变种之前添加了env

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM