forked from mehdicherf/sfdx-BitbucketPipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitbucket-pipelines.yml
139 lines (123 loc) · 5.06 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
image: mehdisfdc/sfdx-cli #image with sfdx installed
#===DEFINITIONS===
definitions:
scripts:
decryptCertificate: &decryptCertificate openssl aes-256-cbc -d -md md5 -in $SERVER_KEY_PATH -out build/server.key -pass pass:$SERVER_KEY_PASSWORD
authToOrg: &authToOrg sfdx force:auth:jwt:grant -s -i $CONSUMERKEY -f build/server.key -u $USERNAME -r $INSTANCE_URL
assignEnvVar: &assignEnvVar export SFDX_USE_GENERIC_UNIX_KEYCHAIN=true && export SFDX_DOMAIN_RETRY=300 && export SFDX_DISABLE_APP_HUB=true && export SFDX_LOG_LEVEL=DEBUG
removeScratchOnlyFolders: &removeScratchOnlyFolders rm -rf force-app/main/default/namedCredentials/
deploy: &deploy sfdx force:source:deploy -p force-app -w 30
deployAndTest: &deployAndTest sfdx force:source:deploy -p force-app -l RunLocalTests -w 30
deployCheckOnly: &deployCheckOnly sfdx force:source:deploy -c -p force-app -l RunLocalTests -w 30
steps:
- step: &pmd-check
name: Code Quality - PMD
script:
#===Download PMD===
- wget https://github.com/pmd/pmd/releases/download/pmd_releases%2F$PMD_VERSION/pmd-bin-$PMD_VERSION.zip
- unzip pmd-bin-$PMD_VERSION.zip
#===Make sure there is no PMD error with a high priority===
- pmd-bin-$PMD_VERSION/bin/run.sh pmd -minimumpriority $PMD_MINIMUM_PRIORITY -d force-app -R custom-apex-rules.xml -f text -l apex
- step: &scratch-check
name: Scratch org Push & Test
script:
#===assign variables===
- *assignEnvVar
- export USERNAME=$PROD_USERNAME
- export CONSUMERKEY=$PROD_CONSUMERKEY
- export INSTANCE_URL=https://login.salesforce.com
- export SERVER_KEY_PATH=build/PROD_server.key.enc
- export SERVER_KEY_PASSWORD=$PROD_KEY_PASSWORD
#===login to Dev Hub===
- *decryptCertificate
- *authToOrg
#===setup scratch org===
- sfdx force:org:create -v $USERNAME --setdefaultusername --definitionfile config/project-scratch-def.json --setalias ciorg --wait 10 --durationdays 1
- sfdx force:org:display -u ciorg
- sfdx force:source:push -u ciorg --json
#===get test results===
- sfdx force:apex:test:run -u ciorg --wait 10
#===delete scratch org===
- sfdx force:org:delete -u ciorg -p
- step: &ci-validate
name: CI sandbox Check-only
script:
#===assign variables===
- *assignEnvVar
- export USERNAME=$CI_USERNAME
- export CONSUMERKEY=$CI_CONSUMERKEY
- export INSTANCE_URL=https://test.salesforce.com
- export SERVER_KEY_PATH=build/CI_server.key.enc
- export SERVER_KEY_PASSWORD=$CI_KEY_PASSWORD
#===remove env specific metadata===
- *removeScratchOnlyFolders
#===auth with target===
- *decryptCertificate
- *authToOrg
#===deploy===
- *deployCheckOnly
- step: &integ-deploy
name: Deploy to INTEG org
script:
#===assign variables===
- *assignEnvVar
- export USERNAME=$INTEG_USERNAME
- export CONSUMERKEY=$INTEG_CONSUMERKEY
- export INSTANCE_URL=https://test.salesforce.com
- export SERVER_KEY_PATH=build/INTEG_server.key.enc
- export SERVER_KEY_PASSWORD=$INTEG_KEY_PASSWORD
#===remove env specific metadata===
- *removeScratchOnlyFolders
#===auth with target===
- *decryptCertificate
- *authToOrg
#===deploy===
- *deploy
- step: &uat-deploy
name: Deploy to UAT org
script:
#===assign variables===
- *assignEnvVar
- export USERNAME=$UAT_USERNAME
- export CONSUMERKEY=$UAT_CONSUMERKEY
- export INSTANCE_URL=https://test.salesforce.com
- export SERVER_KEY_PATH=build/UAT_server.key.enc
- export SERVER_KEY_PASSWORD=$UAT_KEY_PASSWORD
#===remove env specific metadata===
- *removeScratchOnlyFolders
#===auth with target===
- *decryptCertificate
- *authToOrg
#===deploy===
- *deployAndTest
- step: &prod-deploy
name: Deploy to PROD org
script:
#===assign variables===
- *assignEnvVar
- export USERNAME=$PROD_USERNAME
- export CONSUMERKEY=$PROD_CONSUMERKEY
- export INSTANCE_URL=https://login.salesforce.com
- export SERVER_KEY_PATH=build/PROD_server.key.enc
- export SERVER_KEY_PASSWORD=$PROD_KEY_PASSWORD
#===remove env specific metadata===
- *removeScratchOnlyFolders
#===auth with target===
- *decryptCertificate
- *authToOrg
#===deploy===
- *deployAndTest
#===PIPELINES===
pipelines:
default: #this will run for all branches unless specificed otherwise
- parallel:
- step: *pmd-check
- step: *scratch-check
- step: *ci-validate
branches:
develop:
- step: *integ-deploy
release/*:
- step: *uat-deploy
master:
- step: *prod-deploy