[英]Passing Jenkins Pipeline parameter to a Dockerfile
I'm getting a "Bad substitution" error when trying to pass a pipeline parameter to the Dockerfile.尝试将管道参数传递给 Dockerfile 时出现“错误替换”错误。
Jenkins parameter: version Jenkins 参数:版本
Jenkinsfile:詹金斯文件:
pipeline {
agent any
stages {
stage('Build in docker container') {
agent { dockerfile true }
steps {
sh 'node -v'
}
}
}
}
Dockerfile: Dockerfile:
FROM ubuntu:16.04
WORKDIR /root
# install dependencies
RUN apt-get update
RUN apt-get install curl wget vim nano zip git htop ncdu build-essential chrpath libssl-dev libxft-dev apt-transport-https -y
# install node 10
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash
RUN apt-get install --yes nodejs
#RUN node -v
#RUN npm -v
RUN echo ${params.version}
#ARG VERSION
#RUN echo $VERSION
Jenkins error message: Jenkins error message Jenkins 错误消息: Jenkins 错误消息
I'm sure the problem is that im new to pipelines/docker.我确定问题是我对管道/docker 不熟悉。 :) I would be grateful for any help. :) 如果有任何帮助,我将不胜感激。
issue resolved by adding the ARG variable to the Dockerfile.通过将 ARG 变量添加到 Dockerfile 解决了问题。
This is how the Dockerfile looks like:这就是 Dockerfile 的样子:
FROM ubuntu:16.04
WORKDIR /root
# install dependencies
RUN apt-get update
RUN apt-get install curl wget vim nano zip git htop ncdu build-essential chrpath libssl-dev libxft-dev apt-transport-https -y
# install node 10
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash
RUN apt-get install --yes nodejs
#RUN node -v
#RUN npm -v
ARG version=fisticuff
RUN echo $version
and this is how the Jenkinsfile looks like:这就是 Jenkinsfile 的样子:
pipeline {
agent any
stages {
stage('Build in docker container') {
agent {
dockerfile {
additionalBuildArgs '--build-arg version="$version"'
}
}
steps {
sh 'node -v'
}
}
}
}
Console output in Jenkins: Jenkins console output Jenkins 中的控制台 output: Jenkins 控制台 output
Much obliged to all of you for giving me the hints.非常感谢大家给我的提示。 It helped me a lot!这对我帮助很大!
Try running Dockerfile independently first.尝试先独立运行 Dockerfile。 Since you are new to docker try one step at a time.由于您是 docker 的新手,请一次尝试一步。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.