Jenkins Git第一次生成时的更改日志

5f0d552i  于 2022-12-10  发布在  Git
关注(0)|答案(2)|浏览(172)

我有一个Jenkins管道,它根据对特定文件夹的更改触发下游作业。第一次构建时不会触发下游作业。Jenkins日志显示:Warning, empty changelog. Probably because this is the first build.。如何使管道在第一次构建时触发下游作业?

agent { label 'slave-02'}
    options {
        skipDefaultCheckout true }

        stages {
            stage('checkoutscm') {
                steps {
                checkout([$class: 'GitSCM', branches: [[name: "${BRANCH_NAME}"]], doGenerateSubmoduleConfigurations: false, submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'xxxxx', url: 'https://git.xxxx.com/xxx/xxx.git']]])
                }

            }
            stage('DeployRelease') {
                when {
                    anyOf {
                        changeset "scripts/**"
                        changeset "config/**"
                        }
                    }

                    steps {
                        build job: "/DEVOPS_DUMMY/${BRANCH_NAME}", wait: false
        }
    }

         stage('DDLDelivery') {
                when {
                        changeset "DDL/**"
                    }

                    steps {
                        build job: "/PROD/${BRANCH_NAME}", wait: false
            }
        }
    }
} ```
lc8prwob

lc8prwob1#

不知道你用的是哪个git插件,但我在bitbucket插件上遇到了同样的问题。把pr发现策略从Merging the pull request with the current target branch revision改为the current pull request revision就解决了这个问题。

kulphzqa

kulphzqa2#

我试图解决同样的问题,并结束了这个解决方案:

when {
  allOf {
    expression { currentBuild.previousCompletedBuild != null }
    not { changeset 'your-project-dir/**' }
  }
}

检查currentBuild.previousCompletedBuild != null比检查env.BUILD_NUMBER == '1'好(也可以在互联网上找到),因为如果第一次运行由于某些原因而中止,那么下一个构建将有env.BUILD_NUMBER == '2',但它也不会有更改。检查currentBuild.previousCompletedBuild != null保证了之前至少有一个成功的构建,我们可以检查它的更改。

相关问题