forked from forcedotcom/sfdx-bitbucket-package
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitbucket-pipelines.yml
59 lines (59 loc) · 3.46 KB
/
bitbucket-pipelines.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 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.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: atlassian/default-image:2
pipelines:
default: #These commands run for all branches unless specified otherwise
- step:
script:
#Assign variables
- export CLIURL=https://developer.salesforce.com/media/salesforce-cli/sfdx-linux-amd64.tar.xz
- export SFDX_AUTOUPDATE_DISABLE=false
- export SFDX_USE_GENERIC_UNIX_KEYCHAIN=true
- export SFDX_DOMAIN_RETRY=300
- export SFDX_DISABLE_APP_HUB=true
- export SFDX_LOG_LEVEL=DEBUG
- export ROOTDIR=force-app/main/default/
- export TESTLEVEL=RunLocalTests
#Be sure to update the package ID (package ID starts with OHo) or package alias here from the sfdx-project.json file
- export PACKAGENAME="0Ho0N000000CaTDSA0"
- export PACKAGEVERSION=""
#Create sfdx directory
- mkdir sfdx
#Install Salesforce CLI
- wget -qO- $CLIURL | tar xJ -C sfdx --strip-components 1
- "./sfdx/install"
- export PATH=./sfdx/$(pwd):$PATH
- sfdx --version
- sfdx plugins --core
#Install JSON processor
- apt-get install -y jq
#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 Dev Hub
- sfdx force:auth:jwt:grant --clientid $HUB_CONSUMER_KEY --jwtkeyfile assets/server.key --username $HUB_USER_NAME --setdefaultdevhubusername --setalias HubOrg
#Create scratch org
- sfdx force:org:create --targetdevhubusername HubOrg --setdefaultusername --definitionfile config/project-scratch-def.json --setalias ciorg --wait 10 --durationdays 1
- sfdx force:org:display --targetusername ciorg
#Push source to scratch org
- sfdx force:source:push --targetusername ciorg
#Run unit tests on scratch org
- sfdx force:apex:test:run --targetusername ciorg --wait 10 --resultformat tap --codecoverage --testlevel $TESTLEVEL
#Delete scratch org
- sfdx force:org:delete --targetusername ciorg --noprompt
#Create package version
- PACKAGEVERSION="$(sfdx force:package:version:create --package $PACKAGENAME --installationkeybypass --wait 10 --json --targetdevhubusername HubOrg | jq '.result.SubscriberPackageVersionId' | tr -d '"')"
- echo "Package Version Id - "${PACKAGEVERSION}
- echo "Waiting for 5 minutes for package replication"
- sleep 5m
#Create scratch org
- sfdx force:org:create --targetdevhubusername HubOrg --setdefaultusername --definitionfile config/project-scratch-def.json --setalias installorg --wait 10 --durationdays 1
- sfdx force:org:display --targetusername installorg
#Install package in scratch org
- sfdx force:package:install --package $PACKAGEVERSION --wait 10 --targetusername installorg
#Run unit tests on scratch org
- sfdx force:apex:test:run --targetusername installorg --wait 10 --resultformat tap --codecoverage --testlevel $TESTLEVEL
#Delete scratch org
- sfdx force:org:delete --targetusername installorg --noprompt