在管道期间,我需要根据新生成的标签更新版本文件。
我让它工作了,但是由于我正在更新 repo 文件,管道再次运行,这将导致版本文件被更新,这将导致管道再次运行(进入递归行为)。这是我所拥有的:
if (env.GIT_BRANCH == 'master' && !env.CHANGE_TARGET) {
//creeate tag based on next_tag which is calculated prior to this step
dir('./src'){
writeFile file: "version.json", text: "{\"version\":\"${next_tag}\"}"
}
sh 'cat ./src/version.json'
withCredentials([
usernamePassword(
credentialsId: 'sc-github-app',
usernameVariable: 'GITHUB_APP',
passwordVariable: 'GITHUB_TOKEN',
)
]) {
script {
sh 'git config --global url."https://x-oauth-basic:${GITHUB_TOKEN}@github.*****.com/".insteadof https://github.*****.com/'
sh 'git config user.email "GITHUB_APP@******.com"'
sh 'git config --global user.name "GITHUB_APP"'
sh 'git add ./src/version.json'
sh 'git commit -am "update version"'
sh 'git push origin `git rev-parse --abbrev-ref HEAD`:master'
}
}
最后一行确实更新了 repo 中的 version.json 文件,但这将触发管道在 repo 更新后再次运行。
有没有办法在不导致管道再次运行的情况下更新文件?还是有其他方法?