0

在管道期间,我需要根据新生成的标签更新版本文件。

我让它工作了,但是由于我正在更新 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 更新后再次运行。

有没有办法在不导致管道再次运行的情况下更新文件?还是有其他方法?

4

1 回答 1

0

通过使用 github api,您可以在推送之前禁用 webhook,在推送之后您可以再次设置为活动状态。请检查https://docs.github.com/en/rest/reference/repos#update-a-webhook-configuration-for-a-repository

于 2021-02-27T12:28:58.817 回答