-
Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathJenkinsfile
77 lines (58 loc) · 2.59 KB
/
Jenkinsfile
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
#!groovy
node {
def SF_CONSUMER_KEY=env.SF_CONSUMER_KEY
def SF_USERNAME=env.SF_USERNAME
def SERVER_KEY_CREDENTIALS_ID=env.SERVER_KEY_CREDENTIALS_ID
def DEPLOYDIR='src'
def TEST_LEVEL='RunLocalTests'
def SF_INSTANCE_URL = env.SF_INSTANCE_URL ?: "https://test.salesforce.com"
def toolbelt = tool 'toolbelt'
// -------------------------------------------------------------------------
// Check out code from source control.
// -------------------------------------------------------------------------
stage('checkout source') {
checkout scm
}
// -------------------------------------------------------------------------
// Run all the enclosed stages with access to the Salesforce
// JWT key credentials.
// -------------------------------------------------------------------------
withEnv(["HOME=${env.WORKSPACE}"]) {
withCredentials([file(credentialsId: SERVER_KEY_CREDENTIALS_ID, variable: 'server_key_file')]) {
// -------------------------------------------------------------------------
// Authenticate to Salesforce using the server key.
// -------------------------------------------------------------------------
stage('Authorize to Salesforce') {
rc = command "${toolbelt}/sfdx auth:jwt:grant --instanceurl ${SF_INSTANCE_URL} --clientid ${SF_CONSUMER_KEY} --jwtkeyfile ${server_key_file} --username ${SF_USERNAME} --setalias UAT"
if (rc != 0) {
error 'Salesforce org authorization failed.'
}
}
// -------------------------------------------------------------------------
// Deploy metadata and execute unit tests.
// -------------------------------------------------------------------------
stage('Deploy and Run Tests') {
rc = command "${toolbelt}/sfdx force:mdapi:deploy --wait 10 --deploydir ${DEPLOYDIR} --targetusername UAT --testlevel ${TEST_LEVEL}"
if (rc != 0) {
error 'Salesforce deploy and test run failed.'
}
}
// -------------------------------------------------------------------------
// Example shows how to run a check-only deploy.
// -------------------------------------------------------------------------
//stage('Check Only Deploy') {
// rc = command "${toolbelt}/sfdx force:mdapi:deploy --checkonly --wait 10 --deploydir ${DEPLOYDIR} --targetusername UAT --testlevel ${TEST_LEVEL}"
// if (rc != 0) {
// error 'Salesforce deploy failed.'
// }
//}
}
}
}
def command(script) {
if (isUnix()) {
return sh(returnStatus: true, script: script);
} else {
return bat(returnStatus: true, script: script);
}
}