Sample Bitbucket Pipeline Code

Here I am sharing a smaple of Bitbucket Pipeline Code. Please go to this link to check the Bitbucket Pipeline Configuration steps.

Please feel free to connect with me in linkedin, if you have any query related to Bitbucket Pipeline Code / Configuration.

# This file is a sample build configuration for Docker.
# See the guides at https://confluence.atlassian.com/x/O1toN for more examples.
# Only use spaces to indent your .yml configuration.
# --test-level Permissible values are: NoTestRun, RunSpecifiedTests, RunLocalTests, RunAllTestsInOrg
# RunSpecifiedTests: --tests TESTS || - Separate the test names with spaces: --tests Test1 Test2 "Test With Space"
# Reference Link: https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_project_commands_unified.htm
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image:
  name: salesforce/cli:latest-full
pipelines:
  branches:
    feature/*:
      - step:
          name: Build and Validate
          deployment: Deploy_UAT
          script:
          #Assign variables
          - export TESTLEVEL=NoTestRun
          - export TESTLEVEL1=RunLocalTests
          - export TESTLEVEL2=RunSpecifiedTests
          - export TESTS=$(<SpecifiedTest.txt)
          #Decrypt server key
          - openssl enc -nosalt -aes-256-cbc -d -in assets/server.key.enc -out assets/server.key -base64 -K $DECRYPTION_KEY -iv $DECRYPTION_IV
          #Authorize target org
          - sfdx auth:jwt:grant --instance-url $ENDPOINT --client-id $CONSUMER_KEY --jwt-key-file assets/server.key --username $USER_NAME --alias myOrg
          #Install sfdx-git-delta
          - echo y | sf plugins install sfdx-git-delta
          #Findout Delta
          - git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
          - git fetch --all
          - git --no-pager diff --name-status $BITBUCKET_BRANCH origin/develop_UAT
          - sfdx sgd:source:delta --to $BITBUCKET_BRANCH --from origin/develop_UAT --output "."
          #Print Test Class Names
          - echo $TESTS
          #Run a check-only deploy
          #Remove --dry-run to actually deploy the changes
          #If SpecifiedTest File contains only "Default" keyword, it executes "NoTestRun"
          #If SpecifiedTest File contains only Test Class Names separated by spaces, it executes "RunSpecifiedTests"
          #If SpecifiedTest File is empty, it executes "RunLocalTests"
          - if [[ $TESTS != "" ]]; then
          - if [[ $TESTS == "Default" ]]; then
          - sf project deploy start --wait 10 -x package/package.xml --target-org myOrg --test-level $TESTLEVEL --dry-run
          - else
          - sf project deploy start --wait 10 -x package/package.xml --target-org myOrg --test-level $TESTLEVEL2 --tests $TESTS "Test With Space" --dry-run
          - fi
          - else
          - sf project deploy start --wait 10 -x package/package.xml --target-org myOrg --test-level $TESTLEVEL1 --dry-run
          - fi
Unknown's avatar

Author: Jyotirmay Paul

A tech enthusiast!

One thought on “Sample Bitbucket Pipeline Code”

Leave a comment