我正在尝试从Jenkins文件中的两个不同的存储库中提取特定标记。通过从相关管道获取最新的成功构建并使用这些值来确定要签出的标记来确定标记。但是我遇到问题,因为SCM没有替换我添加的withEnv变量。在下面的代码中,您可以看到我正在回显应该是什么标签(这个回声工作正常)但是当涉及到SCM检出标签LAST_SUCCESSFUL_EXTENSIONS_REPO_BUILD和LAST_SUCCESSFUL_SHARED_REPO_BUILD变量没有用它们的值代替
node {
stage('Checkout') {
withEnv([
"LAST_SUCCESSFUL_EXTENSIONS_REPO_BUILD=${ sh ( script: "curl <JENKINS_URL>/job/extensionsrepo/job/${BRANCH_NAME}/lastSuccessfulBuild/buildNumber", returnStdout: true ) }",
"LAST_SUCCESSFUL_SHARED_REPO_BUILD=${ sh ( script: "curl <JENKINS_URL>/job/sharedrepo/job/${BRANCH_NAME}/lastSuccessfulBuild/buildNumber", returnStdout: true ) }"
]) {
sh 'echo ${BRANCH_NAME}_${LAST_SUCCESSFUL_EXTENSIONS_REPO_BUILD}'
sh 'echo ${BRANCH_NAME}_${LAST_SUCCESSFUL_SHARED_REPO_BUILD}'
checkout scm
checkout([
$class: 'GitSCM',
branches: [[name: 'refs/tags/${BRANCH_NAME}_${LAST_SUCCESSFUL_EXTENSIONS_REPO_BUILD}']],
doGenerateSubmoduleConfigurations: false,
extensions: [[
$class: 'RelativeTargetDirectory',
relativeTargetDir: 'app/extensions'
]],
submoduleCfg: [],
userRemoteConfigs: [[
credentialsId: 'ssh-key',
url: '<GIT_URL>'
]]
])
checkout([
$class: 'GitSCM',
branches: [[name: 'refs/tags/${BRANCH_NAME}_${LAST_SUCCESSFUL_SHARED_REPO_BUILD}']],
doGenerateSubmoduleConfigurations: false,
extensions: [[
$class: 'RelativeTargetDirectory',
relativeTargetDir: 'app/shared'
]],
submoduleCfg: [],
userRemoteConfigs: [[
credentialsId: 'ssh-key',
url: '<GIT_URL>'
]]
])
}
}
// test, stage, deploy
}
关于我在这里做错的任何指示都将非常感激。毫无疑问,我没有做到这一点是愚蠢的。
由于
答案 0 :(得分:0)
尝试替换结帐调用中的单引号,其中包含带双引号的分支var。通常,在Groovy中,在包含嵌入变量时应使用双引号(参见What's the difference of strings within single or double quotes in groovy?)。
像:
checkout([
$class: 'GitSCM',
branches: [[name: "refs/tags/${BRANCH_NAME}_${LAST_SUCCESSFUL_EXTENSIONS_REPO_BUILD}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [[
$class: 'RelativeTargetDirectory',
relativeTargetDir: 'app/extensions'
]],
submoduleCfg: [],
userRemoteConfigs: [[
credentialsId: 'ssh-key',
url: '<GIT_URL>'
]]
])