Running Pipelines build for multiple folders in a repository

robotsnoindex

Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.

Summary

There are use cases where you create separate folders within a repo for each of your microservice and you need to run the pipeline build only for the folder (microservice) which is updated.

Solution

Bitbucket pipelines provide an option called "condition" that allows steps to be executed only when a condition or rule is satisfied. Currently, the only condition supported is changesets. Use changesets to execute a step only if one of the modified files matches the expression in includePaths. The file match pattern specified in the includePaths is relative to the $BITBUCKET_CLONE_DIR directory. 

Example:
In the following example, step 1 will only execute if the commit that triggered the pipeline includes changes in XML files inside the path1 directory or any file in the nested directory structure under path2.

- step:
          name: step1
          script:
             - echo "failing paths"
             - exit 1
          condition:
              changesets:
                 includePaths:
                   # only xml files directly under path1 directory
                   - "path1/*.xml"
                   # any changes in deeply nested directories under path2
                   - "path2/**"


Please refer to this document to know more about pipeline conditions. In the below example, when a change is made to the service1 folder, only the microservice1 step will be executed and the microservice2 step will be skipped.

image: atlassian/default-image:3

pipelines:
  default:
    - step:
        name: 'microservice1'
        script:
          - echo "building microservice1"
        condition:
            changesets:
               includePaths:
                   # any changes in deeply nested directories under service1
                  - "service1/**"
    - step:
        name: 'microservice2'
        script:
          - echo "building microservice2"
        condition:
            changesets:
               includePaths:
                   # any changes in deeply nested directories under service2
                  - "service2/**"


Last modified on Mar 7, 2025

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.