JobDSL: an example of configuring a bitbucket source trait of bitbucketForkDiscovery in the multibranchPipelineJob is wanted

1,003 views
Skip to first unread message

Usov Dmitri

unread,
Jan 13, 2020, 5:02:53 AM1/13/20
to Jenkins Users

Hi All, 


I need an example of a JobDSL that can create a Jenkins multi branch pipeline job that is working against Bitbucket and configures the option of bitbucketTrustTeam.


An example that works for me with the "configure" DSL command follows: 

    configure {

        it / 'sources' / 'data' / 'jenkins.branch.BranchSource' / 'source' / traits / 'com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait' {

            strategyId(1)

            trust(class: "com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait\$TrustTeamForks")

        }

    }


What I need is to rewrite it in a more professional way with the pure DSL, something like

                         bitbucketForkDiscovery {

                             strategyId(1)

                             trust(bitbucketTrustTeam)

                         }

but having no success in passing the trust parameter, and having little experience in the matter I would like to ask the community for any help on the subject.


Regards,

Dmitri


An example that needs rewriting is here:


multibranchPipelineJob('my-build') {

    displayName(‘my-build-multi-branch-pipeline')

    description('My project')

    branchSources {

        branchSource {

            source {

                bitbucket {

                     id('my-build-pipeline')

                     serverUrl('https://bitbucket.<domain> ')

                     credentialsId('bitbucket_creds')

                     repoOwner('~myaccount')

                     repository('my_repo')

                     traits {

                         bitbucketBranchDiscovery {

                             strategyId(1)

                         }

                         bitbucketPullRequestDiscovery {

                             strategyId(1)

                         }

//                         bitbucketForkDiscovery {

//                             strategyId(1)

//                             trust(bitbucketTrustTeam)

//                         }

                         bitbucketTagDiscovery()

                     }

                }

            }

            buildStrategies {

                skipInitialBuildOnFirstBranchIndexing()

                buildNamedBranches {

                    filters {

                        regex {

                            regex('master|development|feature-.+|staging-\\d+')

                            caseSensitive(false)

                        }

                    }

               

                }

                buildTags {

                    atLeastDays('0')

                    atMostDays('2')

                }

                buildChangeRequests {

                    ignoreTargetOnlyChanges(false)

                    ignoreUntrustedChanges(true)

                } 

            }

        }

        factory {

            workflowBranchProjectFactory {

                scriptPath('my_build_multibranch.jenkinsfile')

            }

        }

    }

    configure {

        it / 'sources' / 'data' / 'jenkins.branch.BranchSource' / 'source' / traits / 'com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait' {

            strategyId(1)

            trust(class: "com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait\$TrustTeamForks")

        }

    }

    orphanedItemStrategy {

        discardOldItems {

            daysToKeep(30)

            numToKeep(2)

        }

    }

}

Victor Martinez

unread,
Jan 13, 2020, 4:47:25 PM1/13/20
to Jenkins Users
You can use the dynamic DSL that it's specific for your installation, more precisely <your_jenkins_url>/plugin/job-dsl/api-viewer/index.html#method/jenkins.scm.api.SCMSource$$List.bitbucket

Cheers

Usov Dmitri

unread,
Jan 13, 2020, 9:48:00 PM1/13/20
to Jenkins Users
a fully working example will suite
Reply all
Reply to author
Forward
0 new messages