-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJenkinsfile
172 lines (158 loc) · 7.4 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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!groovy
import groovy.json.JsonSlurperClassic
node {
def BUILD_NUMBER = env.BUILD_NUMBER
def RUN_ARTIFACT_DIR = "tests/${BUILD_NUMBER}"
def SFDC_USERNAME
def HUB_ORG = env.HUB_ORG_DH
def SFDC_HOST = env.SFDC_HOST_DH
def JWT_KEY_CRED_ID = env.JWT_CRED_ID_DH
def CONNECTED_APP_CONSUMER_KEY = env.CONNECTED_APP_CONSUMER_KEY_DH
println 'KEY IS'
println JWT_KEY_CRED_ID
println HUB_ORG
println SFDC_HOST
println CONNECTED_APP_CONSUMER_KEY
stage('checkout source code ') {
checkout scm
}
withCredentials([file(credentialsId: JWT_KEY_CRED_ID, variable: 'jwt_key_file')]) {
stage('Create Scratch Org') {
if (isUnix()) {
rc = sh returnStatus: true, script: "sfdx force:auth:jwt:grant --clientid ${CONNECTED_APP_CONSUMER_KEY} --username ${HUB_ORG} --jwtkeyfile ${jwt_key_file} -d --instanceurl ${SFDC_HOST}"
} else {
rc = bat returnStatus: true, script: "sfdx force:auth:jwt:grant --clientid ${CONNECTED_APP_CONSUMER_KEY} --username ${HUB_ORG} --jwtkeyfile \"${jwt_key_file}\" -d --instanceurl ${SFDC_HOST}"
}
if (rc != 0) {
error 'hub org authorization failed'
}
println(rc)
/*if (isUnix()) {
scratchorg = sh returnStdout: true, script: "sfdx force:org:create -f ./config/project-scratch-def.json --json -a ci-cd-org -s -w 10 -d 30"
} else {
scratchorg = bat returnStdout: true, script: "sfdx force:org:create -f ./config/project-scratch-def.json --json -a ci-cd-org -s -w 10 -d 30"
}
println('scratchorg')
println(scratchorg)*/
/*def jsonSlurper = new JsonSlurperClassic()
def robj = jsonSlurper.parseText(scratchorg)
println('rObj');
println(robj);
if (robj.status != 0) {
error 'org creation failed: ' + robj.message
}
SFDC_USERNAME = robj.result.username
println(SFDC_USERNAME)
robj = null*/
}
stage('Convert Salesforce DX and Store in SRC Folder') {
if (isUnix()) {
println(' Convert SFDC Project to normal project')
srccode = sh returnStdout: true, script : "sfdx force:source:convert -r force-app -d ./src"
} else {
println(' Convert SFDC Project to normal project')
srccode = bat returnStdout: true, script : "sfdx force:source:convert -r force-app -d ./src"
}
println(srccode)
}
stage('Push To Target Org') {
if(isUnix()){
println(' Deploy the code into Scratch ORG.')
sourcepush = sh returnStdout: true, script : "sfdx force:mdapi:deploy -d ./src -u ${HUB_ORG}"
}else{
println(' Deploy the code into Scratch ORG.')
sourcepush = bat returnStdout: true, script : "sfdx force:mdapi:deploy -d ./src -u ${HUB_ORG}"
}
/*if (isUnix()) {
println(' Deploy the code into Scratch ORG.')
sourcepush = sh returnStdout: true, script: "sfdx force:source:push -u ci-cd-org"
println(' Assign the Permission Set to the New user ')
permset = sh returnStdout: true, script: "sfdx force:user:permset:assign -n yeurdreamin -u ci-cd-org"
} else {
println(' Deploy the code into Scratch ORG.')
sourcepush = bat returnStdout: true, script: "sfdx force:source:push -u ci-cd-org"
println(' Assign the Permission Set to the New user ')
permset = bat returnStdout: true, script: "sfdx force:user:permset:assign -n yeurdreamin -u ci-cd-org"
}*/
println(sourcepush)
if(isUnix()){
println('Checking Deployment Status');
statusDep = sh returnStdout: true, script: "sfdx force:mdapi:deploy:report -u ${HUB_ORG} --json"
}else{
println('Checking Deployment Status');
statusDep = bat returnStdout: true, script: "sfdx force:mdapi:deploy:report -u ${HUB_ORG} --json"
}
println(' Deployment Status ')
println(statusDep)
if(isUnix()){
println('Waiting For 60 Seconds')
sleep 60
}else{
println('Waiting For 60 Seconds')
sleep 60
}
if(isUnix()){
println('Checking Deployment Status Again ');
statusDep1 = sh returnStdout: true, script: "sfdx force:mdapi:deploy:report -u ${HUB_ORG} --json"
}else{
println('Checking Deployment Status Again');
statusDep1 = bat returnStdout: true, script: "sfdx force:mdapi:deploy:report -u ${HUB_ORG} --json"
}
println('Updated Deployment Status')
println(statusDep1)
/*def jsonSlurper = new JsonSlurperClassic()
def robj = jsonSlurper.parseText(statusDep.toString())
println('rObj');
println(robj);
if (robj.status != 0) {
println(robj.message)
}
SFDC_USERNAME = robj.status
println(SFDC_USERNAME)
robj = null*/
if (sourcepush != 0) {
//error 'push failed'
}
if(isUnix()){
println(' Assign the Permission Set to the New user ')
permset = sh returnStdout: true, script: "sfdx force:user:permset:assign -n deloitteAdv -u ${HUB_ORG} --json"
}else{
println(' Assign the Permission Set to the New user ')
permset = bat returnStdout: true, script: "sfdx force:user:permset:assign -n deloitteAdv -u ${HUB_ORG} --json"
}
println(permset)
if (permset != 0) {
//error 'permission set assignment failed'
}
}
stage('Import Data to test ORG') {
if (isUnix()) {
println(' importing data to test org')
dataimport = sh returnStdout: true, script: "sfdx force:data:tree:import --plan ./data/data-plan.json -u ${HUB_ORG} --json"
} else {
println(' importing data to test org.')
dataimport = bat returnStdout: true, script: "sfdx force:data:tree:import --plan ./data/data-plan.json -u ${HUB_ORG} --json"
}
//println(dataimport)
if (dataimport != 0) {
println(dataimport)
}
}
stage('Run Local Test Classes') {
if (isUnix()) {
testStatus = sh returnStdout: true, script: "sfdx force:apex:test:run --testlevel RunLocalTests -u ${HUB_ORG}"
} else {
//testStatus = sh returnStdout: true, script: "sfdx force:apex:test:run --testlevel RunLocalTests -u ${HUB_ORG} --json"
}
//println(testStatus)
}
stage('Open Target ORG') {
if (isUnix()) {
openorg = sh returnStdout: true, script: "sfdx force:org:open -u ${HUB_ORG} --json"
} else {
openorg = bat returnStdout: true, script: "sfdx force:org:open -u ${HUB_ORG} --json"
}
println(openorg)
}
}
}