Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Pipeline trigger based on branch

Eric Muelbredt
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!
June 23, 2025

Hello,

it is not quite clear to me what the structure of the yml file is for different branches.

I need the possibility to run different validation jobs per branch.

If I create a PullRequest against stage, the validation job of develop still runs.


image: node:18

pipelines:
pull-requests:
'**->develop':
- step:
name: "Validate for PR to develop"
caches:
- node
script:
- echo "Installing Salesforce CLI..."
- npm install --global @Salesforce/cli
- echo "Installing sfdx git delta plugin..."
- echo y | sf plugins:install sfdx-git-delta
- sf plugins
- echo "Authenticating with Salesforce using authURL for develop (PR)..."
- echo "$SF_AUTH_URL_DEV" > authfile.txt
- sfdx auth:sfdxurl:store --sfdx-url-file authfile.txt --setalias devOrg --setdefaultusername
- echo "Creating delta packages for new, modified or deleted metadata..."
- mkdir -p changed-sources
- sf sgd:source:delta --to "HEAD" --from "origin/develop" --output changed-sources/ --generate-delta --source force-app/ -i .forceignore
- chmod +x ./deployment/script/*.sh
- echo "Running validation script for develop..."
- ./deployment/script/validate.sh devOrg

'**->stage':
- step:
name: "Validate for PR to stage"
caches:
- node
script:
- echo "Installing Salesforce CLI..."
- npm install --global @Salesforce/cli
- echo "Installing sfdx git delta plugin..."
- echo y | sf plugins:install sfdx-git-delta
- sf plugins
- echo "Authenticating with Salesforce using authURL for stage (PR)..."
- echo "$SF_AUTH_URL_STAGE" > authfile.txt
- sfdx auth:sfdxurl:store --sfdx-url-file authfile.txt --setalias stageOrg --setdefaultusername
- echo "Creating delta packages for new, modified or deleted metadata..."
- mkdir -p changed-sources
- sf sgd:source:delta --to "HEAD" --from "origin/stage" --output changed-sources/ --generate-delta --source force-app/ -i .forceignore
- chmod +x ./deployment/script/*.sh
- echo "Running validation script for stage..."
- ./deployment/script/validate.sh stageOrg

1 answer

0 votes
Brita Moorus
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 23, 2025

Hi! 👋

Bitbucket Pipelines doesn’t recognize '**->branch' syntax for pull-request triggers. Instead, the correct way to specify a PR trigger for a branch is just the branch name, like this:

pull-requests:
develop:
- step:
...
stage:
- step:
...

You can also check Atlassian's documentation on Pipeline start conditions: https://support.atlassian.com/bitbucket-cloud/docs/pipeline-start-conditions/ 

Let me know if this helps! ✨

Eric Muelbredt
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!
June 24, 2025

Hi,

If I adopt your syntax and create a pull request against develop, nothing happens. So no job is executed.

Saxea _Flowie_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 24, 2025

Hi @Eric Muelbredt

The syntax matches against the source branch, not the target branch.

You might want to have a look at Flowie, a Bitbucket app we provide, which gives you more control over the pipelines trigger. It supports trigger based on target branch like you are trying to achieve, for instance.

Eric Muelbredt
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!
June 24, 2025

Found a solution.

image: node:18

pipelines:

pull-requests:

'**': # Wildcard triggers for all PRs

- step:

name: "Validate PR for develop, stage or main"

caches:

- node

script:

- |

echo "Source Branch: $BITBUCKET_PR_SOURCE_BRANCH"

echo "Target Branch: $BITBUCKET_PR_DESTINATION_BRANCH"

echo "Installing Salesforce CLI..."

npm install --global @salesforce/cli

echo "Installing sfdx git delta plugin..."

echo y | sf plugins:install sfdx-git-delta

sf plugins

# Branch-based environment detection

if [ "$BITBUCKET_PR_DESTINATION_BRANCH" = "develop" ]; then

echo "Authenticating with Salesforce using authURL for develop (PR)..."

echo "$SF_AUTH_URL_DEV" > authfile.txt

sfdx auth:sfdxurl:store --sfdx-url-file authfile.txt --setalias devOrg --setdefaultusername

ORG_ALIAS="devOrg"

FROM_BRANCH="origin/develop"

elif [ "$BITBUCKET_PR_DESTINATION_BRANCH" = "stage" ]; then

echo "Authenticating with Salesforce using authURL for stage (PR)..."

echo "$SF_AUTH_URL_STAGE" > authfile.txt

sfdx auth:sfdxurl:store --sfdx-url-file authfile.txt --setalias stageOrg --setdefaultusername

ORG_ALIAS="stageOrg"

FROM_BRANCH="origin/stage"

elif [ "$BITBUCKET_PR_DESTINATION_BRANCH" = "main" ]; then

echo "Authenticating with Salesforce using authURL for production (PR)..."

echo "$SF_AUTH_URL_PROD" > authfile.txt

sfdx auth:sfdxurl:store --sfdx-url-file authfile.txt --setalias prodOrg --setdefaultusername

ORG_ALIAS="prodOrg"

FROM_BRANCH="origin/main"

else

echo "❌ Unsupported PR target branch: $BITBUCKET_PR_DESTINATION_BRANCH. Aborting."

exit 1

fi

echo "Creating delta packages for new, modified or deleted metadata..."

mkdir -p changed-sources

sf sgd:source:delta --to "HEAD" --from "$FROM_BRANCH" --output changed-sources/ --generate-delta --source force-app/ -i .forceignore

echo "Running validation script..."

chmod +x ./deployment/script/*.sh

./deployment/script/validate.sh "$ORG_ALIAS"
Like Brita Moorus likes this
Brita Moorus
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 24, 2025

Glad to hear you found a solution! 😊

Suggest an answer

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

Atlassian Community Events