跨阶段设置和引用Jenkins脚本化管道中的变量



我正试图通过使用withEnv和稍后在Checkout Stage中的引用设置变量(GIT_ORG(来确定Github组织,但无法做到这一点,我使用Jenkins Scripted Pipeline和"node"和多个"Stage"来实现这一点。当前作业在克隆Git存储库时失败,因为签出时没有有效的${Git_ORG}。我还想跨阶段使用withEnv变量,不知道如何做到这一点。感谢您的帮助。谢谢

stage( 'Checkout - TIBCO BW') {
sh '/app/aims/scripts/folder.sh'
sh 'echo "Checkout TIBCO BW CODE"'
if (env.MDM_BW == 'true') {
withEnv(["GIT_ORG=Enterprise-MDM"]){
echo env.GIT_ORG
}
} else {
withEnv(["GIT_ORG=Enterprise-Integrations"]){
echo $GIT_ORG
}
}                    
checkout([$class: 'GitSCM', 
branches: [[name: '$GIT_CODE_TAG']], 
doGenerateSubmoduleConfigurations: false, 
extensions: [[$class: 'RelativeTargetDirectory', 
relativeTargetDir: '${TIBCO_EARNAME}/code']], 
submoduleCfg: [], 
userRemoteConfigs: [[credentialsId: 'GIT_USER', url: 'git@github.company.com:${GIT_ORG}/${TIBCO_EARNAME}.git']]])
//workspaceUpdater: [$class: 'UpdateUpdater']])
}

尝试以下脚本:

if (env.MDM_BW == 'true') {
environment{
GIT_ORG=Enterprise-MDM
}
} else {
environment{
GIT_ORG=Enterprise-Integrations
}
} 

最新更新