在设置 Jenkins 多分支管道时,我想“排除作为 PR 归档的分支”,除了某些分支,我想同时构建 PR 和原始分支。
使用 MASTER 的示例:
您可以按名称过滤多分支作业设置中的分支。
包含某些分支比较棘手,因为 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
}
}
}
}