Jenkins工作dsl为bitbucket分支源插件文档与完整的例子?

z9ju0rcb  于 2022-12-03  发布在  Jenkins
关注(0)|答案(4)|浏览(150)

我目前拥有:

multibranchPipelineJob("myjob") {
  branchSources {
    branchSource {
      source {
        bitbucket {
          credentialsId('bitbucket-login-user-pass')
          repoOwner('myteam')
          repository('myrepo')
          autoRegisterHook(true)
        }
      }
    }
  }
}

但我还需要添加以下设置:

我如何在配置中添加这些设置?它们是“特性”吗?我在哪里可以看到我有哪些可用的特性?

cuxqih21

cuxqih211#

你可以查看jenkins-instance的jobDSL-API-Viewer,它会显示你的示例中所有可用的jodDSL函数(jobDSL用于已安装的插件):
https://your.jenkins.url/plugin/job-dsl/api-viewer/index.html

omtl5h9j

omtl5h9j2#

这是我使用的(用organizationFolder Package 的bitbucket):

organizationFolder('example') {
    description('This contains branch source jobs for Bitbucket')
    displayName('The Organization Folder')
    triggers {
        periodic(86400)
    }
    organizations {
        bitbucket {
          repoOwner('myorg')
          credentialsId('BITBUCKET_CRED')
          autoRegisterHooks(false)
          traits {
            sourceRegexFilter {
              // A Java regular expression to restrict the project names.
              regex('.*')
            }
          }
        }
    }
    properties {
        mavenConfigFolderOverrideProperty {
            override(true)
            settings {
                settingsConfigId('DEFAULT_MAVEN_SETTINGS')
            }
        }
    }
    // discover Branches (workaround due to JENKINS-46202)
    configure { node ->
        // node represents <jenkins.branch.OrganizationFolder>        
        def traits = node / 'navigators' / 'com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMNavigator' / 'traits'
        traits << 'com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait' {
            strategyId(3) // detect all branches
        }
    }    
}
zzzyeukh

zzzyeukh3#

multibranchPipelineJob('example'){
    branchSources{
      branchSource{
        source{
          bitbucket{
            repoOwner(project)
            repository(name)
            credentialsId('git_user')
            traits {
              bitbucketBranchDiscovery{
                strategyId(1)
              }
            }            
          }
        }
      }
    }

其中traits在DSL文档中定义,strategyId的正确值我在bitbucket插件源代码中找到。
从这里一定很容易发现其他的选择。

w1jd8yoj

w1jd8yoj4#

我认为@prumand提供了最好的方式来调查工作dsl,下面我从我的Angular 添加示例单个repo多分支管道:

multibranchPipelineJob('/myjob') {

        factory {
            workflowBranchProjectFactory {
                scriptPath('Jenkinsfile')
            }
        }

        branchSources {
          branchSource {
            source {
              bitbucket {
               id('123456789')
               serverUrl('https://bitbucket.org')
               credentialsId('bitbucket-access-id')
               repoOwner('myGroupOrUser')
               repository('myRepository')
               autoRegisterHook(true) // or not

                traits {
                  bitbucketBranchDiscovery {
                    strategyId(3) // 1 - exclude branches that are also filled as PRs, 3 - all branches
                  }
                  bitbucketPullRequestDiscovery {
                    strategyId(1) // 1 - merging PR with the current target branch revision, 2 - current pull request revision
                  }
                }
              }
            }
          }
        }

        orphanedItemStrategy {
          discardOldItems {
            numToKeep(3)
          }
        }

        triggers {
          periodicFolderTrigger {
            interval('86400000') // 1 day
          }
        }

      }

相关问题