This repository has been archived by the owner on Feb 17, 2024. It is now read-only.
/
Jenkinsfile
executable file
·168 lines (141 loc) · 6.18 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
/* Before using this example, check if the below release tag is the latest.
* You can find the latest release tag at https://git.soma.salesforce.com/dci/sfci-pipeline-sharedlib/releases
*/
// @Library('sfci-pipeline-sharedlib@v0.14.44') _
@Library('sfci-pipeline-sharedlib@master') _
/* import is required only if you use one of the classes specified here:
* https://git.soma.salesforce.com/dci/sfci-pipeline-sharedlib#classes
*/
import net.sfdc.dci.BuildUtils
import net.sfdc.dci.NotifyUtils
import groovy.json.JsonSlurper
// Api Docs:
// https://git.soma.salesforce.com/pages/dci/sfci-pipeline-sharedlib/net/sfdc/dci/package-summary.html
// Are all of these api docs from Carbon needed for lighning inspector
import groovy.json.JsonOutput
import net.sfdc.dci.BuildUtils
import net.sfdc.dci.CodeCoverageUtils
import net.sfdc.dci.GitHubUtils
import net.sfdc.dci.JenkinsUtils
import net.sfdc.dci.LogUtil
import net.sfdc.dci.MavenUtils
import net.sfdc.dci.NotifyUtils
def releaseParameters = {
parameters([
booleanParam( defaultValue: false,
description: 'Deploy master build to chrome store.',
name: 'DEPLOY'),
])
};
def envDef = [
buildImage: 'ops0-artifactrepo1-0-prd.data.sfdc.net/dci/sfci-lightning-tools-docker:latest',
stopSuccessEmail: true,
releaseParameters: releaseParameters
]
// Lightning Tooling profile used for staging artifcats to Nexus.
// def STAGING_PROFILE_ID = 'c599a6860aec7';
env.RELEASE_BRANCHES = ['master']
env.GUS_TEAM_NAME = "Lightning Tooling";
// Code coverage reporting settings.
def coverage_config = [
// Can also use jacoco
tool_name : 'clover',
// Literally what the name of your team is in Gus.
gus_team_name : env.GUS_TEAM_NAME,
test_suite : 'unit',
language_type : 'javascript',
aggregate_team_coverage: true,
dev_gus_upload : false,
report_location : 'logs/jest-coverage/clover.xml'
]
// is there a reason to define vars here?
def vars;
executePipeline(envDef) {
stage('Init') {
/**
* Log information about the run for debugging purposes later.
*/
sh "node --version"
sh "google-chrome --version"
buildInit()
checkout scm
}
stage('NPM') {
stage('Initialize') {
npmInit()
sh 'yarn config set proxy http://public0-proxy1-0-prd.data.sfdc.net:8080'
sh 'yarn config set https-proxy http://public0-proxy1-0-prd.data.sfdc.net:8080'
}
stage('NPM Install') {
sh 'yarn install --frozen-lockfile --ignore-engines'
}
stage('NPM Build') {
sh 'yarn build'
archiveArtifacts artifacts: 'builds/*'
}
}
stage('Run Tests') {
// Lets run these commands in Parellel
parallel([
failFast: false,
"Unit Tests": {
sh 'yarn run test:ci'
}
])
}
stage('JS Code Coverage Reporting') {
// Publish what Jest outputs
publishHTML([
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: false,
reportDir: 'logs/jest-report/',
reportFiles: 'index.html',
reportName: 'JEST Results',
reportTitles: ''
])
publishHTML([
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: false,
reportDir: 'logs/jest-coverage/',
reportFiles: 'index.html',
reportName: 'JEST Coverage',
reportTitles: ''
])
/**
* Upload the Clover report from the jest --coverage run
*/
CodeCoverageUtils.uploadReportForGusDashboard(this, coverage_config)
}
stage('Deploy') {
sh "curl --version"
if (env.BRANCH_NAME ==~ /deploy/ || (env.DEPLOY && env.DEPLOY.toBoolean() == true)) {
withCredentials([
string(credentialsId: 'prod_chrome_client_id', variable: 'CLIENT_ID'),
string(credentialsId: 'prod_chrome_client_secret', variable: 'CLIENT_SECRET'),
string(credentialsId: 'prod_chrome_refresh_token', variable: 'REFRESH_TOKEN')]) {
def clientIdString = "client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}&refresh_token=${REFRESH_TOKEN}&grant_type=refresh_token"
def cmd = "curl --tlsv1.2 \"https://accounts.google.com/o/oauth2/token\" -d \"${clientIdString}\" | ./dev/jq-linux64 -r .access_token"
def ACCESS_TOKEN = sh(script: cmd, returnStdout: true).trim()
def FILE = "lightning-inspector-latest.zip"
def APP_ID = "pcpmcffcomlcjgpcheokdfcjipanjdpc";
def upload = sh(script: "curl --tlsv1.2 -H \"Authorization: Bearer ${ACCESS_TOKEN}\" -H \"x-goog-api-version: 2\" -X PUT -T ${FILE} -v \"https://www.googleapis.com/upload/chromewebstore/v1.1/items/${APP_ID}\"", returnStdout: true).trim()
def uploadResult = sh( script: "echo '${upload}' | ./dev/jq-linux64 -r .uploadState", returnStdout: true).trim()
if (uploadResult != "SUCCESS") {
error("Upload failed with result ${upload}")
}
def publish = sh(script: "curl --tlsv1.2 -H \"Authorization: Bearer ${ACCESS_TOKEN}\" -H \"x-goog-api-version: 2\" -H \"Content-Length: 0\" -X POST -v \"https://www.googleapis.com/chromewebstore/v1.1/items/${APP_ID}/publish\"", returnStdout: true).trim()
def publishResult = sh( script: "echo '${publish}' | ./dev/jq-linux64 -r .status[0]", returnStdout: true).trim()
if (publishResult != "OK") {
error("Publish failed with result ${publish}")
}
def version = sh( script: "cat package.json | ./dev/jq-linux64 -r .version", returnStdout: true).trim()
sh "git tag -a deployed-${version} -m \"Build\""
sh "git push origin deployed-${version}"
}
} else {
echo "Did not deploy because branch name did not contain 'deploy'";
}
}
}