BitBucket
Bitbucket Pull Request comments
To avoid having to open job logs to see deployment errors, sfdx-hardis can post them as a comment on the Pull Request UI.
To use this capability:
- Go to Repository Settings -> Access Tokens and create a Repository Access Token with the following scopes:
- pullrequest
- pullrequest:write
- repository
- repository:write
- Go to Repository Settings -> Repository Variables and create a variable named CI_SFDX_HARDIS_BITBUCKET_TOKEN with the access token as value
Every time you create a Pull Request, the CI job posts its result as a comment.
- Example with deployment success
Notes:
- This integration works with the sfdx-hardis pipeline, but also with home-made pipelines: just call sf hardis:project:deploy:start instead of
sf project:deploy:start.
- This integration uses the following variables:
- CI_SFDX_HARDIS_BITBUCKET_TOKEN
- BITBUCKET_WORKSPACE
- BITBUCKET_REPO_SLUG
- BITBUCKET_BRANCH
- BITBUCKET_PR_ID
- BITBUCKET_BUILD_NUMBER
One job at a time per org (optional)
Salesforce runs one deployment at a time in an org. With this setting, the deployment checks, the major branch deployment check and the deployments of an org wait for each other in the CI queue, instead of waiting in the org while their job runs. More details in One job at a time per org.
It is off by default. To turn it on, in bitbucket-pipelines.yml, uncomment the concurrency-group line of the steps Simulate SFDX deployment, Check Major Branch Deployment and Deploy to major org. The jobs of a group run one at a time, first in, first out.
If your pipeline files were created with an older version of sfdx-hardis, add the lines below to them.
bitbucket-pipelines.yml, one line in each of the three steps, at the level of name:
- step:
name: Simulate SFDX deployment
concurrency-group: deploy-$BITBUCKET_PR_DESTINATION_BRANCH
- step:
name: Check Major Branch Deployment
concurrency-group: deploy-$BITBUCKET_BRANCH
- step:
name: Deploy to major org
concurrency-group: deploy-$BITBUCKET_BRANCH
Using Bitbucket integration from Jenkins
When running on Jenkins, sfdx-hardis automatically detects the Jenkins environment and maps its variables to Bitbucket equivalents. You only need to set:
| Variable | Description |
|---|---|
| CI_SFDX_HARDIS_BITBUCKET_TOKEN | A Bitbucket repository access token with scopes pullrequest, pullrequest:write, repository, repository:write, stored as a Jenkins credential |
The following variables are automatically derived from Jenkins built-in variables:
BITBUCKET_WORKSPACE,BITBUCKET_REPO_SLUG: parsed fromGIT_URL(git remote)BITBUCKET_BRANCH: fromGIT_BRANCH/CHANGE_BRANCHBITBUCKET_BUILD_NUMBER: fromBUILD_NUMBERBITBUCKET_PR_ID: fromCHANGE_ID(Jenkins Multibranch Pipeline)- Job URL: from
BUILD_URL
Instructions for using Coding Agents
When using auto-fix with coding agents, the pipeline must be able to push a fix branch and create/update Pull Requests.
This works for both:
- Bitbucket Cloud
- Bitbucket Data Center / Server (on-premise)
Add this in your pipeline script before running sf hardis:* commands:
- |
if [ -n "${CI_SFDX_HARDIS_BITBUCKET_TOKEN:-}" ]; then
git config user.email "sfdx-hardis-bot@cloudity.com"
git config user.name "sfdx-hardis Bot"
ORIGIN_PATH=$(git remote get-url origin | sed -E 's#^https?://##; s#^git@([^:]+):#\1/#; s#^ssh://git@([^/]+)/#\1/#; s#\.git$##')
git remote set-url origin "https://x-token-auth:${CI_SFDX_HARDIS_BITBUCKET_TOKEN}@${ORIGIN_PATH}.git"
echo "[sfdx-hardis] Bitbucket push/PR auth enabled for coding agents"
else
echo "[sfdx-hardis] Skipping coding-agent Bitbucket auth setup: CI_SFDX_HARDIS_BITBUCKET_TOKEN is not set"
fi
Required secret/variable:
CI_SFDX_HARDIS_BITBUCKET_TOKEN:- Go to Repository Settings -> Access Tokens.
- Create a repository access token with scopes:
pullrequest,pullrequest:write,repository,repository:write. - Store it as a secured repository variable named
CI_SFDX_HARDIS_BITBUCKET_TOKEN.
