【发布时间】:2019-03-16 09:13:06
【问题描述】:
我有一个 脚本化 管道,其中一个阶段我需要根据 shell 脚本的输出设置当前构建的结果。不幸的是,使用 shell 脚本设置值并不会改变使用withEnv 创建的变量的值。
是否有人能够在下面的简化 sn-p 中指出错误(如果有)或提出其他解决方案?
stage('MyStage') {
withEnv(["MY_VAR=null"]) {
if (env.someCondition1 || env.someCondition2) {
sh '''#!/bin/bash
echo $MY_VAR # null
export MY_VAR="UNSTABLE"
printenv | grep MY_VAR # MY_VAR="UNSTABLE"
'''
}
echo env.MY_VAR // null
currentBuild.result = env.MY_VAR
echo currentBuild.result // FAILURE
}
}
【问题讨论】:
标签: bash jenkins environment-variables jenkins-pipeline