Jenkins Multibranch - 排除也是 PR 的分支*例外*

问题描述 投票:0回答:1

在设置 Jenkins 多分支管道时,我想“排除作为 PR 归档的分支”,除了某些分支,我想同时构建 PR 和原始分支。

使用 MASTER 的示例:

  • 为 STORY-999 建立 PR
    • 公关建立
    • STORY-999 没有
  • 为 MASTER 建立 PR
    • 公关建立
    • MASTER 也建成了
git jenkins pull-request multibranch-pipeline
1个回答
0
投票

您可以按名称过滤多分支作业设置中的分支。

包含某些分支比较棘手,因为 Jenkins 在经典作业中没有此设置。

但是使用 Jenkinsfile,你可以尝试进行测试:

node {
    stage('Check Branch') {
        script {
            // Check if branch is filed as a PR
            if (env.CHANGE_ID) {
                echo "This branch is filed as a PR."

                // Check if branch is MASTER or another special branch
                if (env.BRANCH_NAME == 'MASTER' || env.BRANCH_NAME == 'special-branch') {
                    echo "This is a special branch. Running build."
                    // Your build steps here
                } else {
                    echo "This is not a special branch. Skipping build."
                }
            } else {
                echo "This branch is not filed as a PR. Running build."
                // Your build steps here
            }
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.