Skip to content

Instantly share code, notes, and snippets.

@jkentjnr
Created November 21, 2022 09:21
Show Gist options
  • Save jkentjnr/96337ba3ae28856fff9bba6551bfe2d8 to your computer and use it in GitHub Desktop.
Save jkentjnr/96337ba3ae28856fff9bba6551bfe2d8 to your computer and use it in GitHub Desktop.
Azure DevOps Pipeline Template for Salesforce DX Sandbox Deployment
# ----------------------------------------------------------------------------------------------------
# SFDX Deploy
# ----------------------------------------------------------------------------------------------------
parameters:
pool: {}
jobs:
- deployment: sfdx_deploy
displayName: SFDX Deploy
environment: ${{ parameters.Environment }}
pool: ${{ parameters.pool }}
timeoutInMinutes: 360
strategy:
runOnce:
deploy:
steps:
- checkout: self
- task: DownloadSecureFile@1
name: sfdxDigitalCertificate
inputs:
secureFile: salesforce_privatekey.pem
- task: NodeTool@0
inputs:
versionSpec: '16.x'
displayName: 'Install Node.js'
- script: |
npm install @salesforce/cli sfdx-cli --global
sfdx --version
displayName: 'Install Salesforce DX'
- script: |
sfdx force:auth:jwt:grant --clientid $SFDX_CLIENT_ID --jwtkeyfile $(sfdxDigitalCertificate.secureFilePath) --username $SFDX_USERNAME --setalias targetorg
displayName: 'Authenticate Salesforce Instance'
- script: |
sfdx force:source:convert -d mdapi-source/unlocked-package
displayName: 'Generate Metadata'
- script: |
sfdx force:mdapi:deploy -d mdapi-source/unlocked-package --ignoreerrors -u targetorg -l RunLocalTests -w 15 --json --junit > ./build.json
displayName: 'Deploy'
- script: |
SFDX_BUILD_ID=$(jq -r '.result.id' ./build.json)
sfdx force:source:deploy:report -i $SFDX_BUILD_ID -u targetorg
echo
cat ./build.json
condition: always()
timeoutInMinutes: 1
displayName: 'Print Build Report'
- script: |
SFDX_TEST_OUTPUT_PATH=$(jq -r '.result.junit' ./build.json)
echo "##vso[task.setvariable variable=SFDX_TEST_OUTPUT_PATH]$SFDX_TEST_OUTPUT_PATH"
condition: always()
timeoutInMinutes: 1
displayName: 'Locate Test Report'
- task: PublishTestResults@2
displayName: 'Publish Test Result'
condition: always()
timeoutInMinutes: 1
inputs:
testRunner: JUnit
testResultsFiles: $(SFDX_TEST_OUTPUT_PATH)
testRunTitle: "[${{ parameters.instance }}] Salesforce Deployment"
failTaskOnFailedTests: true
platform: ${{ parameters.instance }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment