没有BASH的Jenkins Pipeline Step withEnv无法正常工作 [英] Jenkins Pipeline Step withEnv does not work without BASH
问题描述
我无法在Jenkins管道中为容器设置环境变量. 看来,"withEnv"在没有bash的机器上不能很好地工作.
I've trouble setting an environment variable for a container in an Jenkins pipeline. It seems, that "withEnv" does not work nicely with machines without bash.
您可以确认吗?我找不到官方声明;-)
Can you confirm that? I cannot find an official statement ;-)
当我在Jenkins从站上运行以下代码片段时,它可以工作. 但是,在没有BASH的docker容器中执行该命令时,未设置"$ test".
When I run the following snippet on the Jenkins slave it works. But when it is executed in a docker container without BASH "$test" isn't set.
withEnv(["test='asd'"]){
sh 'echo $test'
}
推荐答案
如果我没记错的话,我认为该变量设置不正确.
If I'm not mistaken, I believe the variable is not set correctly.
尝试一下:
withEnv(["test=asd"]){
sh "echo \$test"
}
在Jenkins管道中:
Within a Jenkins pipeline:
$var = Groovy parameter
\$var (within a sh closure) = Bash parameter
${var} = also refers to Groovy parameter
要将groovy变量插入bash变量中:
In order to insert a groovy variable into a bash variable:
sh ("VAR=${GROOVY_VAR}")
在sh闭包内使用bash变量:
Using a bash variable inside a sh closure:
sh (" echo \$BASH_VAR")
这篇关于没有BASH的Jenkins Pipeline Step withEnv无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!