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.
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! ✨
Hi,
If I adopt your syntax and create a pull request against develop, nothing happens. So no job is executed.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Glad to hear you found a solution! 😊
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.