How to configure Bamboo plans to be triggered by specific repository directories

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

This article covers steps to implement a use-case scenario where multiple directories are inside a single repository, and a commit to each particular directory should trigger a different build plan in Bamboo. This implementation uses Regular Expressions to work with file patterns for the build triggers.

Environment

Tested on Bamboo versions 8 and 9 with a plan configured to be triggered after a change on the repository.

Solution

On the repository settings, you can configure the Change detection options with include or exclude file & message commit patterns that Bamboo can use to decide whether to trigger the build. For example, adding a ^(bamboo-specs)\/.* to the exclude changeset will instruct Bamboo to ignore any commits to files within the bamboo-specs folder.

It will be necessary to manually scan the repository to apply the changes later.

Since Bamboo uses regular expressions, it's possible to configure it to ignore all files, but still accept one, and then effectively trigger the build. For example, the following regular expression will ignore any commits to the bamboo-specs folder, except for the bamboo.yaml file, so a build will be triggered whenever a commit is made to that specific file.

^((bamboo-specs)\/(?!bamboo\.yaml).*$)

This can be seen in the following <bamboo-home>/logs/atlassian-bamboo.log log file:

Bamboo logs
2022-11-08 23:56:59,680 INFO [15-BAM::SpecsDetection:pool-18-thread-1] [AllTypesSpecsImporter] Bamboo Specs import took 3.275 s
2022-11-08 23:56:59,849 INFO [10-BAM::PlanExec:pool-12-thread-4] [DefaultChangeDetectionManager] : Excluded 1 file(s) from commit 508e7476d8bcbbf516a75988fd3e9335a16bbe44
2022-11-08 23:56:59,850 INFO [10-BAM::PlanExec:pool-12-thread-4] [ChangeDetectionListenerAction] No changes found for 'ABC-EL'

You can also exclude changesets by adding regular expressions that Bamboo will match as the commit message and will then bypass any builds.

For example, adding ^nobuild.*$ to the Exclude changesets will tell Bamboo that any commit message that starts with the word "nobuild" will be ignored.

If you have multiple repositories linked to a build plan, other repositories' changes can still trigger the build plan. Please review your build plans triggers to determine which other repositories can trigger a build.


Simple example

Suppose Bitbucket has a project with the following repository and directories in its structure:

  • Project: ProjectTest
    • Repository: RepositoryTest
      • DirectoryTest1
      • DirectoryTest2

Additionally, Bamboo is configured as follows:

  • PlanTest is set to trigger after changes from the Bitbucket RepositoryTest are committed.

With the scenario above, if a change is committed on any Directories in the RepositoryTest, both will trigger the Bamboo PlanTest. If you'd like to trigger the PlanTest only when a change was applied to DirectoryTest1, for example, and ignore the changes from DirectoryTest2, the File pattern can be used to achieve that. To apply the solution:

  1. Go to Bamboo cog icon > Linked repositories
  2. Expand the Change detection options for the repository in question
  3. Add the DirectoryTest1 in the File pattern field as follows: 

    ^Directory1\/*



Last modified on Jul 4, 2024

Was this helpful?

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