Declare a Multibranch Pipeline

JFrog Pipelines Documentation

Products
JFrog Pipelines
Content Type
User Guide
ft:sourceType
Paligo

Note

This topic is part of the process of creating a multibranch pipeline. For more information see Creating Multibranch Pipelines.

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.

pipelines_resources.yml

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_steps.yml

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}}"

Note

When used in a conditional or comparison logic, {{gitBranch}} placeholders must be wrapped within double quotes.

Example: {{ if eq "{{gitBranch}}" "master" }}