Jenkins Blue Ocean多分支流水线排除develop分支不生效怎么办?

A. 建梗 阅读 25

我在用Blue Ocean创建多分支流水线时想排除develop分支,按文档在Pipeline Script里写了excludeBranches: ['develop'],但运行时提示hudson.plugins.git.GitException: Failed to connect to repository,develop分支还是被扫描到了。我试过在Jenkinsfile加ignore-on-push参数也不行,谁能教我正确的排除方法?

我的配置大概是这样的:


pipeline {
    agent any
    triggers { pollSCM 'H/5 * * * *' }
    options {
        skipDefaultCheckout true
        disableConcurrentBuilds()
    }
    stages {
        stage('Build') { ... }
    }
}

检查过分支名称确认没错,但就是不生效,是不是排除语法有问题?或者需要在其他配置页面设置?

我来解答 赞 3 收藏
二维码
手机扫码查看
2 条解答
Mr-爱娜
Mr-爱娜 Lv1
排除分支的配置不在Pipeline Script里,应该在多分支流水线的配置页面设置。具体是在“Branch Sources”下的“Behaviors”里添加“Filter by name (with wildcards)”,然后填上!develop

如果你非要在Jenkinsfile里处理,可以试试这样写:

properties([
[$class: 'PipelineTriggersJobProperty', triggers: [
[$class: 'SCMTrigger', scmpoll_spec: 'H/5 * * * *', ignorePostCommitHooks: true]
]],
pipelineTriggers([pollSCM('H/5 * * * *')]),
disableConcurrentBuilds(),
[$class: 'IgnoreOnPushNotificationProperty', branches: ['develop']]
])


建议还是用第一种方法,更直观靠谱。
点赞
2026-02-16 14:04
UX燕燕
UX燕燕 Lv1
excludeBranches要写在pipeline外面,和triggers同级,正确格式是:

pipeline {
agent any
triggers { pollSCM 'H/5 * * * *' }
options {
skipDefaultCheckout true
disableConcurrentBuilds()
}
}

// 注意这个位置!!!
excludeBranches(['develop'])


Branch Indexing的时候会读这个配置,写在pipeline里面就无效了。
点赞 5
2026-02-04 14:05