Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Suggestions To Debug Pipeline Triggering Issues

Michael Murphy
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 18, 2024 edited

Hello All,

We are just getting into pipelines and I've been trying to configure a pipeline to run a maven spotless plugin goal for all PRs on a specific branch without success.

pipelines:
pull-requests:
<INSERT_BRANCH_NAME_HERE>:
- step:
name: Spotless Check
image: maven:3.6.3
caches:
- maven
script:
mvn spotless:check
condition:
changesets:
includePaths:
- <INERT_DIRECTORY_HERE>/**

The bitbucket-pipelines.yml is in the root of the repository (e.g. a repository named central), INSERT_BRANCH_NAME_HERE would be the target branch the PR is being merged into (e.g. a branch named release/v1.0) and INSERT_DIRECTORY_HERE would be a directory the pipeline is limited to (e.g. a directory called support).

If I create a PR from "release/v1.0-TICKET_NUMBER" into "release/v1.0" which contains a modification to "support/src/Helper.java" I would have expected it to trigger a pipeline build, but that isn't the case. If I trigger the pipeline manually the build fails or succeeds correctly (depending on the formatting of the change). The manual build is also associated with the PR (seen on the right hand side of the bitbucket PR).

Any suggestions on debugging a pipeline triggering issue as such?

Thanks,

MM

1 answer

1 accepted

1 vote
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 20, 2024

Hi Michael and welcome to the community!

Pull-requests pipelines get triggered based on the source branch, not the destination branch. When you have a definition like the one you shared, the pull-requests pipeline will get triggered when a PR with <INSERT_BRANCH_NAME_HERE> as a source branch gets created (and later, when the source branch of this PR gets updated with new commits).

We have a feature request for pull-requests pipelines based on the destination branch here:

You can add your vote to that feature request and add yourself as a watcher if you'd like to get notified via email on updates.

In the meantime, you could use a workaround like the following:

pipelines: 
pull-requests:
'**':
- step:
script:
- if [ "${BITBUCKET_PR_DESTINATION_BRANCH}" != "release/v1.0" ]; then exit 0; fi
- <some other command>

The '**' trigger will trigger the pipeline for all PRs. You can adjust it so that it runs only when certain branch patterns match the PR's source branch. The build then checks the destination branch of the PR that triggered the build. If it is different than release/v1.0, the exit 0 command will make the pipeline stop.

 

Please also keep in mind the following:

1. Manual pipelines run differently than pull-requests pipelines.

If you trigger a pipeline manually on a branch, then only this branch will be cloned in the Docker container where the build runs. So, the build will run on the source code of that branch.

A pull-requests pipeline, on the other hand, will clone the PR's source branch, and then merge the PR's destination branch into the source branch (in the Docker container where the build runs, not in the Bitbucket repo). So, the build will run on the merged code.

2. The condition option with changesets also behaves differently.

In a pull-requests pipeline, all commits are taken into account, and if you provide an includePaths list of patterns, the step or stage will be executed when at least one commit change matches one of the conditions.

For other types of pipelines (including pipelines that you run manually on a branch), only the last commit is considered.

Please feel free to reach out if you have any questions.

Kind regards,
Theodora

Michael Murphy
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 21, 2024

Theodor, Thanks for the detailed answer. I've voted/watched BCLOUD-17859 in hopes that it will be implemented someday (source branch triggering isn't as useful as target branch triggering, developers can name branches pretty much anything, all targeting the same branch). I've updated our pipeline as you suggested and it looks promising. Thanks!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Upcoming Bitbucket Events