tagging docker images with Jenkins pipeline parameter
我正在尝试标记我的docker映像`。我正在使用Jenkins通过声明一个字符串参数来为我做这件事。
在
我收到一个错误消息,说标签不正确。
在我的Jenkins管道中,我有一个名为
我正在使用蓝绿色部署。
您可以在管道中使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | # Jenkinsfile --- stage('build'){ node('vagrant'){ withEnv([ 'VERSION=0.1' ]){ git_checkout() dir('app'){ ansiColor('xterm') { sh 'mvn clean install' } } // build docker image with version sh 'docker build --rm -t app:${VERSION} .' } } } def git_checkout(){ checkout([ $class: 'GitSCM', branches: [[name: '*/' + env.BRANCH_NAME]], doGenerateSubmoduleConfigurations: false, extensions: [ [$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: true, recursiveSubmodules: false, reference: '', trackingSubmodules: true], [$class: 'AuthorInChangelog'], [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false] ], submoduleCfg: [], userRemoteConfigs: [ [credentialsId: '...', url: 'ssh://vagrant@ubuntu18/usr/local/repos/app.git'] ] ]) } |
1 2 3 4 5 6 7 8 9 10 11 | # Dockerfile --- FROM ubuntu:18.04 RUN apt update && \\ apt install -y openjdk-11-jre && \\ apt clean COPY app/special-security/target/special-security.jar /bin ENTRYPOINT ["java","-jar","/bin/special-security.jar"] |
在Jenkins构建环境中设置的版本号由
注意:我使用
问题
In my Jenkins pipeline I have a string parameter named version with default LASTEST. However I want to be able to enter v1 or v2 and that is the tag the container uses.
假设docker compose在您的Jenkins管道内部运行,则
解决方案
很抱歉,但是我对Jenkins并不熟悉,所以我无法告诉您如何在运行shell环境中正确设置
小费
作为
1 | image: api:"${version:-latest}" |
或者如果您想要显式错误
1 | image: api:"${version? Mipssing version for docker image!!!}" |