CI / CD Salesforce - Bitbucket ENVIRONMENT variables issues in pipelines

Hermann Ouré October 7, 2024

I am trying to setup it CI/CD for salesforce using bitbucket.

I have create a connected app for each environments (qa, uat, production)

And in bitbucket > repository settings > deployments:

I have added the sandboxes for staging environment and the production environment. For each environment I have set ENVIRONMENT variables:

USERNAME
CONSUMER_KEY
LOGIN_URL
ENVIRONMENT

Like this:

Screenshot 2024-10-07 100605.png

but when I push a commit to test the deployment, the ENVIRONMENT variable returns an error.

ENVIRONMENT variable is not set

I use echo in the script to be able to log the error and $ENVIRONMENT is empty.

set -e
# echo is used to print the message on the console
echo "Starting the build process for environment: $ENVIRONMENT"

if [ -z "$ENVIRONMENT" ]; then
    echo "ENVIRONMENT variable is not set."
    exit 1
fi

Currently the build fails here when I have clearly created the ENVIRONMENT variable:

Screenshot 2024-10-06 153635.png

finally these are the deployment steps in the bitbucket-pipelines.yml:

# Production deployment
release/master:
  - step: *build-pipeline
  - step: *destructive-pre
  - step: *deploy-full-package
  - step: *deploy-env-spec-config
  - step: *destructive-post

I also tried adding deployment to the steps as shown below:

# Production deployment
release/master:
 deployment: production
 steps:
  - step: *build-pipeline
  - step: *destructive-pre
  - step: *deploy-full-package
  - step: *deploy-env-spec-config
  - step: *destructive-post

But when doing so, another error occurs:

There is an error in your bitbucket-pipelines.yml at [pipelines > branches > release/master > deployment]. This section should not contain "deployment".


How can I fix these errors?

Thanks

1 answer

1 vote
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 8, 2024

Hi Hermann and welcome to the community!

Since you are using YAML anchors, if you want to set the deployment environment for the build-pipeline step that runs on the release/master branch pipeline, then the syntax should be as follows:

pipelines:
branches:
release/master:
- step:
<<: *build-pipeline
deployment: production
- step: *destructive-pre
- step: *deploy-full-package
- step: *deploy-env-spec-config
- step: *destructive-post

where production is the name of an environment you have configured in Repository settings > Deployments.

This syntax is mentioned in the following documentation:

https://support.atlassian.com/bitbucket-cloud/docs/yaml-anchors/

Do you want to use the production deployment environment only for the build-pipeline step, or also for the rest of this pipeline's steps?

Kind regards,
Theodora

Hermann Ouré October 8, 2024

Hello Theodora,
Thanks for your reply.
I need to use the production deployment environment for all the pipelines steps.
Thanks

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 8, 2024

Hi Hermann,

You will then need to use a stage for all the steps of the release/master pipeline and define the deployment on the stage level, like below:

pipelines:
branches:
release/master:
- stage:
name: Some name for this stage
deployment: production
steps:
- step: *build-pipeline
- step: *destructive-pre
- step: *deploy-full-package
- step: *deploy-env-spec-config
- step: *destructive-post

Stages allow you to use a certain deployment environment in multiple steps of the same pipeline. This feature is documented here:

Please feel free to let me know how it goes.

Kind regards,
Theodora

Hermann Ouré October 8, 2024

Hello Theodora,
It worked, 
Thank you very much

Like # people like this
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 9, 2024

You are very welcome, Hermann!

Please feel free to reach out if you ever need anything else!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Product Admin Site Admin
TAGS
AUG Leaders

Atlassian Community Events