Examples

2 minute read
The starting point is the BranchSource object, so configurations always start with branchSource:.
For more information on how to configure various options related to Multibranch Pipelines via YAML syntax, refer to Multibranch Pipeline Template syntax.

GitHub

  • gitHubBranchDiscovery: This example applies a behavior that discovers branches, excluding branches that are also filed as PRs.

  • gitHubPullRequestDiscovery and gitHubForkDiscovery: This example applies behaviors that -

    • discover pull requests backed by branches in the origin repository by merging the pull request with the current revision of the target branch.

    • discover pull requests backed by branches in forked repositories by merging the pull request with the current revision of the target branch.

    • only accept Jenkinsfile changes from users with admin or write permission to the repository on GitHub.

  • gitHubSshCheckout: This example applies a behavior that forces GitHub checkouts to use the ssh:// protocol.

gitHubBranchDiscovery
gitHubPullRequestDiscovery and gitHubForkDiscovery
gitHubSshCheckout
multibranch: branchSource: github: repoOwner: 'organization' repository: 'repository' credentialsId: 'github-credentials' traits: - gitHubBranchDiscovery: strategyId: 1
multibranch: branchSource: github: repoOwner: 'organization' repository: 'repository' credentialsId: 'github-credentials' traits: - gitHubPullRequestDiscovery: strategyId: 1 - gitHubForkDiscovery: strategyId: 1 trust: $class: TrustPermission
multibranch: branchSource: github: repoOwner: 'organization' repository: 'repository' credentialsId: 'github-credentials' traits: - gitHubSshCheckout: credentialsId: 'github-ssh-credentials-id'

Git

  • This example applies behaviors that discover all branches and refs matching the pattern custom/team/*, and cleans the workspace before every checkout, and explicitly configures GitHub to be the repository browser for the project.

    multibranch: branchSource: git: remote: 'https://github.com/owner/repo.git' credentialsId: 'git-credentials' traits: - gitBranchDiscovery - $class: DiscoverOtherRefsTrait ref: 'custom/team/*' - cleanBeforeCheckout - $class: GitBrowserSCMSourceTrait browser: $class: GithubWeb repoUrl: 'https://github.com/owner/repo'

Bitbucket

  • bitbucketBranchDiscovery: This example applies a behavior that discovers branches, excluding branches that are also filed as PRs.

  • bitbucketPullRequestDiscovery and bitbucketForkDiscovery: This example applies a behavior that discovers pull requests backed by branches in the origin repository by merging the pull request with the current revision of the target branch in addition to a behavior that discovers pull requests backed by branches in forked repositories by merging the pull request with the current revision of the target branch, and that only accepts Jenkinsfile changes from forks belonging to the same account as the origin repository.

  • bitbucketSshCheckout: This example applies a behavior that forces GitHub checkouts to use the ssh:// protocol.

bitbucketBranchDiscovery
bitbucketPullRequestDiscovery and bitbucketForkDiscovery
bitbucketSshCheckout
multibranch: branchSource: bitbucket: repoOwner: 'organization' repository: 'repository' credentialsId: 'bitbucket-credentials' traits: - bitbucketBranchDiscovery: strategyId: 1
multibranch: branchSource: bitbucket: repoOwner: 'organization' repository: 'repository' credentialsId: 'github-credentials' traits: - bitbucketPullRequestDiscovery: strategyId: 1 - bitbucketForkDiscovery: strategyId: 1 trust: $class: TrustTeamForks
multibranch: branchSource: bitbucket: repoOwner: 'organization' repository: 'repository' credentialsId: 'bitbucket-credentials' traits: - bitbucketSshCheckout: credentialsId: 'bitbucket-ssh-credentials'

Property Strategies

DefaultBranchPropertyStrategy
NamedExceptionBranchPropertyStrategy
multibranch: branchSource: github: repoOwner: 'organization' repository: 'repository' credentialsId: 'github-credentials' strategy: $class: DefaultBranchPropertyStrategy props: - $class: NoTriggerBranchProperty strategy: INDEXING
multibranch: branchSource: github: repoOwner: 'organization' repository: 'repository' credentialsId: 'github-credentials' strategy: $class: NamedExceptionsBranchPropertyStrategy namedExceptions: - $class: Named name: main props: - $class: DurabilityHintBranchProperty hint: MAX_SURVIVABILITY defaultProperties: - $class: DurabilityHintBranchProperty hint: PERFORMANCE_OPTIMIZED