multibranchPipelineJob作业DSL:如何启用“发现”分支和禁止自动SCM触发

时间:2019-05-24 11:42:01

标签: jenkins jenkins-job-dsl multibranch-pipeline

如何在Jenkins作业DSL中为多分支管道启用行为发现工作台和属性策略禁止自动SCM触发

enter image description here

2 个答案:

答案 0 :(得分:1)

只是为了扩展接受的答案:您不需要那种棘手的 traits << ... 语法来添加分支(或标签)发现。相反,您可以使用 traits { } 部分(请参阅 docs)。

multibranchPipelineJob 'job name', {
    branchSources {
        branchSource {
            source {
                git {
                    id 'job name'
                    remote 'git@<repo-url>.git'
                    credentialsId 'git-creds-id'

                    traits {
                        gitBranchDiscovery()
                        gitTagDiscovery() // if you need tag discovery
                    }
                }
            }
            strategy {
                defaultBranchPropertyStrategy {
                    props {
                        noTriggerBranchProperty()
                    }
                }
            }
        }
    }
}

答案 1 :(得分:0)

可以这样做:

multibranchPipelineJob('job name') {
    branchSources {
        branchSource {
            source {
                git {
                    remote('https://<repo address>.git')
                    credentialsId('credential id')
                }
            }
            strategy {
                defaultBranchPropertyStrategy {
                    props {
                        noTriggerBranchProperty()
                    }
                }
            }
        }
    }
    configure {
        def traits = it / sources / data / 'jenkins.branch.BranchSource' / source / traits
        traits << 'jenkins.plugins.git.traits.BranchDiscoveryTrait' {}
    }
    triggers {
        periodic(2) // Trigger every 2 min.
    }
    orphanedItemStrategy { discardOldItems { numToKeep(-1) } }
}