更新时间:2023-12-05 14:38:40
更新
您可以使用环境变量而无需environment {}
You can use environment variable without having environment {}
使用类似我在这里使用的环境变量(我对您的代码进行了一些重构).对外壳程序脚本使用三重单引号进行循环并向其添加grrovy变量:
Use environment variables like the ones i have used here (i refactored your code a little bit). Using triple single quotes for shell script for loop and adding grrovy variable to it:
def callfunc() {
sh '''
export s="key"
echo $s
for i in $VARENV1
do
echo "Looping ... i is set to $i"
done
'''
}
pipeline {
agent { label 'agent_1' }
stages {
stage ('Run script') {
steps {
script {
env.VARENV1 = "Peace"
}
callfunc()
}
}
}
}
输出: