[英]Passing Jenkins Pipeline parameter to a Dockerfile
尝试将管道参数传递给 Dockerfile 时出现“错误替换”错误。
詹金斯文件:
pipeline {
agent any
stages {
stage('Build in docker container') {
agent { dockerfile true }
steps {
sh 'node -v'
}
}
}
}
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 错误消息: Jenkins 错误消息
我确定问题是我对管道/docker 不熟悉。 :) 如果有任何帮助,我将不胜感激。
通过将 ARG 变量添加到 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
ARG version=fisticuff
RUN echo $version
这就是 Jenkinsfile 的样子:
pipeline {
agent any
stages {
stage('Build in docker container') {
agent {
dockerfile {
additionalBuildArgs '--build-arg version="$version"'
}
}
steps {
sh 'node -v'
}
}
}
}
Jenkins 中的控制台 output: Jenkins 控制台 output
非常感谢大家给我的提示。 这对我帮助很大!
尝试先独立运行 Dockerfile。 由于您是 docker 的新手,请一次尝试一步。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.