Ale*_*nin 1 jenkins jenkins-pipeline
Jenkins 不想在代理 docker args 部分中使用任何变量,除了主要的 Jenkins 变量,例如JENKINS_URL.
容器化 Jenkins 2.152。尝试使用变量使用自定义参数启动 docker 代理。尝试使用 Groove var, environment var like env.Var, environment var like ${Var}。所有这些都被用作名称,而不是它们的值。
詹金斯档案
Gpath = "/var/log:/opt/gpath"
pipeline {
agent {
docker {
image "bash:latest"
args '--network proxy_nw -v Gpath -v ${Ppath} -v env.Ppath2 -v /var/log:/${NODE_LABELS}'
}
}
environment {
Ppath = "/var/log:/opt/ppath"
Ppath2 = "/var/log:/opt/ppath2"
}
stages {
stage ('main') {
steps {
script {
sh 'echo "Ppath= " ${Ppath} "; Ppath2= " ${Ppath2} "; NODE_LABELS= " ${NODE_LABELS}'
sh 'printenv'
input message: "wait"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
詹金斯控制台输出
docker run -t -d -u 1000:1000 --network proxy_nw -v Gpath -v ${Ppath} -v env.Ppath2 -v /var/log:/${NODE_LABELS}
Run Code Online (Sandbox Code Playgroud)
如您所见,我在 args 部分中使用了几个变量。好的,由于单引号,Groovy 变量像名称一样看起来很合理。我们可以在 Jenkins 控制台输出中看到它。但是环境变量也不起作用。它们实际上在 docker 容器内可用,而不是在 Jenkins 级别。
那么,如何为代理 docker 指令的 args 部分定义变量?
我找到了解决方法。
我添加到顶层agent none并将我的所有阶段放入舞台中,只需容器声明。是的,这是因为我们可以把stages里面stage
pipeline {
agent none
environment {
WORKDIR = getVar(G_workdir)
DIRDOUBLE = getVar(G_dirdouble)
}
stages {
stage('build container up') {
agent {
docker {
image G_container
args '--network proxy_nw -v ${DIRDOUBLE}'
}
}
stages {
stage('Initialise') {
steps {
........
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3984 次 |
| 最近记录: |