Configuring a Multibranch Pipeline Source
A multibranch pipeline must be in a pipeline source that has been configured as multibranch.
When a multibranch pipeline source syncs, it automatically creates and destroys pipeline config files in branches from the main branch. You can specify Exclude and Include Branch Patterns to limit which branches participate in automatic pipeline creation/deletion.
For more information, see Managing Pipeline Sources.
Declaring a Multibranch Pipeline
In Pipelines DSL, the term {{gitBranch}}
can be used as a placeholder for whatever branch the pipeline was loaded from. When Pipelines syncs from the pipeline source, it automatically replaces any occurrence of {{gitBranch}}
with the name of the branch. Note that this will occur for single branch pipeline sources as well as multbranch ones).
When creating a multibranch pipeline in Pipelines DSL, use {{gitBranch}}
as the value anywhere you would designate a branch. When Pipelines syncs each of the branches of a multibranch pipeline source, it will automatically replace the {{gitBranch}}
reference in each branch's pipeline with the name of its branch.
In the GitRepo resource definition, use {{gitBranch}}
where you define the branches of that resource to include.
resources: - name: appRepo type: GitRepo configuration: gitProvider: my_github path: myrepo/myproject branches: include: ^{{gitBranch}}$ # Formatted as a regex pattern
You can also use {{gitBranch}}
anywhere you might refer to a branch in steps or pipeline configuration. This example pipeline outputs the name of the branch.
pipelines: - name: multibranch_example steps: - name: mb_step_1 type: Bash configuration: affinityGroup: together inputResources: - name: appRepo execution: onExecute: - echo "running test for branch {{gitBranch}}" - pushd $res_tw_multibranch_repo_resourcePath - ls -latr - popd - name: mb_step_2 type: Bash configuration: affinityGroup: together inputSteps: - name: mb_step_1 execution: onExecute: - echo "building {{gitBranch}}"
When used in a conditional or comparison logic, {{gitBranch}}
placeholders must be wrapped within double quotes.
Example: {{ if eq "{{gitBranch}}" "master" }}
Running Multibranch Pipelines
A multibranch pipeline synced from a multibranch pipeline source appears in My Pipelines as an expandable entry in the list. Click to expand a multibranch pipeline source and then click one of the branch versions to view and run it.
With your branch chosen, you can view the Pipeline Run Logs of any run in that branch.
The example multibranch pipeline above uses {{gitBranch}}
to output the name of the branch being run. You can see the results of this in the run logs of the pipeline in each branch.