首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >什么是JCasc / Job选项,用于“将更改推送到BitBucket时生成”标志?

什么是JCasc / Job选项,用于“将更改推送到BitBucket时生成”标志?
EN

Stack Overflow用户
提问于 2021-11-02 16:24:08
回答 1查看 506关注 0票数 2

我正在尝试使用jenkins 舵图,它使用Jcasc和JobDSL来进行作业配置。我已经配置了organizationFolder,其中包含bitbucket配置,它遍历我的bitbucket repos并创建multibranchPipeline作业。看起来不错,可以从bitbucket接收webhooks,但不会触发作业。

代码语言:javascript
复制
ue Nov 02 14:49:53 UTC 2021] Received com.cloudbees.jenkins.plugins.bitbucket.hooks.PushHookProcessor$1 
UPDATED event from 10.0.0.112 ⇒ http://zzzzzzzzz:8080/bitbucket-scmsource-hook/notify with timestamp Tue Nov 02 14:49:53 UTC 2021
Connecting to https://bitbucket.org using zzzzzzzzzz/******
Repository type: Git
Looking up bddevteam83/infra-system for branches
Checking branch master from zzzzzzzzzzz/zzzzzz-system
      'Jenkinsfile' found
    Met criteria
Changes detected: master (null → d57b19309533ffd5133f88eb3809d1ad3896bfc8)
Did not schedule build for branch: master

我怀疑这是由于未经检查

当更改被推到BitBucket时,multibranchPipeline配置中的“multibranchPipeline Build”标志。

问题:哪个JobDSL选项支持“在将更改推送到BitBucket时生成”标志?

我的配置是基于这个例子的,如下所示

代码语言:javascript
复制
                organizationFolder('bitbucket') {
                    description("Bitbucket organization folder configured with JCasC")
                    displayName('bitbucket')

                    properties {
                        noTriggerOrganizationFolderProperty {
                            branches('develop')
                        }
                    }

                    // "Projects"
                    organizations {
                        bitbucket {
                            serverUrl("https://bitbucket.org/")
                            repoOwner("zzzzzzzzzzz")
                            credentialsId("bitbucket-http")
                            // "Traits" ("Behaviours" in the GUI) that are "declarative-compatible"
                            traits {
                                webhookRegistrationTrait {
                                    mode('ITEM')
                                }
                                submoduleOptionTrait {
                                    extension {
                                        disableSubmodules(false)
                                        recursiveSubmodules(true)
                                        trackingSubmodules(false)
                                        reference(null)
                                        timeout(null)
                                        parentCredentials(true)
                                    }
                                }
                            }
                        }
                    }
                    // "Traits" ("Behaviours" in the GUI) that are NOT "declarative-compatible"
                    // For some 'traits, we need to configure this stuff by hand until JobDSL handles it
                    // https://issues.jenkins.io/browse/JENKINS-45504
                    configure { node ->
                        def traits = node / navigators / 'com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMNavigator' / traits
                        // Discover branches
                        traits << 'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait' {
                            strategyId('1')
                            // Values
                            //  1 : Exclude branches that are also filed as PRs
                            //  2 : Only branches that are also filed as PRs
                            //  3 : All branches
                        }
                        traits << 'com.cloudbees.jenkins.plugins.bitbucket.SSHCheckoutTrait' {
                            credentialsId('bitbucket-git-ssh-key')
                        }
                        // Filter by name (with regular expression)
                        traits << 'jenkins.scm.impl.trait.RegexSCMSourceFilterTrait' {
                            regex('.*')
                        }
                        // Discover pull requests from origin
                        traits << 'com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait' {
                            strategyId('1')
                            // Values
                            // 1 : Merging the pull request with the current target branch revision
                            // 2 : The current pull request revision
                            // 3 : Both the current pull request revision and the pull request merged with the current target branch revision
                        }
                        // Discover pull requests from forks
                        traits << 'com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait' {
                            strategyId('1')
                            // Values
                            // 1 : Merging the pull request with the current target branch revision
                            // 2 : The current pull request revision
                            // 3 : Both the current pull request revision and the pull request merged with the current target branch revision
                            trustID('1')
                            // Values
                            // 0 : Everyone
                            // 1 : Forks in the same account
                            // 2 : Nobody
                        }

                        traits << 'jenkins.scm.impl.trait.RegexSCMHeadFilterTrait' {
                            regex('(master)|(develop)|(development)|(integration)|(release.*)')
                        }

                    }
                    // "Project Recognizers"
                    projectFactories {
                        workflowMultiBranchProjectFactory {
                            scriptPath 'Jenkinsfile'
                        }
                    }
                    // "Orphaned Item Strategy"
                    orphanedItemStrategy {
                        discardOldItems {
                            daysToKeep(30)
                            numToKeep(100)
                        }
                    }
                    // "Scan Organization Folder Triggers" : 1 day
                    // We need to configure this stuff by hand because JobDSL only allow 'periodic(int min)' for now
                    configure { node ->
                        node / triggers / 'com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger' {
                            spec('H H * * *')
                            interval(86400000)
                        }
                    }

//// the below config I added seems to have no effect on "Build when a change is pushed to BitBucket"

                    configure { node ->
                        node / triggers / 'com.cloudbees.jenkins.plugins.BitBucketMultibranchTrigger' {
                          overrideUrl('')
                        }
                    }
                    configure { node ->
                        node / triggers / 'com.cloudbees.jenkins.plugins.BitBucketTrigger' {
                          overrideUrl('')
                        }
                    }

                }

UPD:通过Web配置任何东西都不是一种选择,一切都必须作为代码来管理。

EN

回答 1

Stack Overflow用户

发布于 2022-03-31 16:10:01

这都是关于在https://github.com/jenkinsci/branch-api-plugin/blob/master/src/main/resources/jenkins/branch/NoTriggerOrganizationFolderProperty/help-branches.html中使用分支方法的

允许您控制来自分支索引的SCM提交触发器。

代码语言:javascript
复制
organizationFolder(...) {
  ...
  properties {
    noTriggerOrganizationFolderProperty {
      // automatically trigger builds for branches matching this regex at index time
      branches('PR-\\d+')
    }
  }

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69813779

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档