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
ENVIRONMENTLike this:
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
fiCurrently the build fails here when I have clearly created the ENVIRONMENT variable:
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-postI 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-postBut 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
Community moderators have prevented the ability to post new answers.
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
Hello Theodora,
Thanks for your reply.
I need to use the production deployment environment for all the pipelines steps.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
You are very welcome, Hermann!
Please feel free to reach out if you ever need anything else!
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.