簡體   English   中英

將 Jenkins 管道參數傳遞給 Dockerfile

[英]Passing Jenkins Pipeline parameter to a Dockerfile

嘗試將管道參數傳遞給 Dockerfile 時出現“錯誤替換”錯誤。

Jenkins 參數:版本

詹金斯文件:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM