forked from zowe/zowe-explorer-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
173 lines (163 loc) · 5.67 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
173
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/
/**
* List of people who will get all emails for master builds
*/
def MASTER_RECIPIENTS_LIST = "[email protected]"
/**
* Name of the master branch
*/
def MASTER_BRANCH = "master"
/**
* TOKEN ID where secret is stored
*/
def PUBLISH_TOKEN = "vsce-publish-key"
/**
* TOKEN ID where secret is stored
*/
def ZOWE_ROBOT_TOKEN = "zowe-robot-github"
def PIPELINE_CONTROL = [
ci_skip: false
]
/**
* Options for the pipeline
*/
def opts = []
opts.push(buildDiscarder(logRotator(numToKeepStr: '10')))
if (BRANCH_NAME == MASTER_BRANCH) opts.push(disableConcurrentBuilds())
opts.push( parameters([
booleanParam(name: 'SKIP_CI_SKIP', defaultValue: false, description: 'Skip: CI SKIP'),
booleanParam(name: 'SKIP_TEST', defaultValue: false, description: 'Skip: TEST'),
booleanParam(name: 'SKIP_AUDIT', defaultValue: false, description: 'Skip: AUDIT'),
booleanParam(name: 'SKIP_PUBLISH', defaultValue: false, description: 'Skip: PUBLISH'),
string(name: 'RECIPIENTS_LIST', defaultValue: '', description: 'List of emails to receive build results (Override)')
]) )
properties(opts)
pipeline {
agent { label 'ca-jenkins-agent' }
stages {
stage('Check for CI Skip') {
when { allOf {
expression { return !params.SKIP_CI_SKIP }
} }
steps {
timeout(time: 2, unit: 'MINUTES') { script {
def result = sh returnStatus: true, script: 'git log -1 | grep \'.*\\[ci skip\\].*\''
if (result == 0) {
echo '"ci skip" spotted in the git commit. Aborting.'
PIPELINE_CONTROL.ci_skip = true
}
} }
}
}
stage('Install dependencies') {
when { allOf {
expression { return !PIPELINE_CONTROL.ci_skip }
} }
steps {
timeout(time: 10, unit: 'MINUTES') { script {
sh "npm install"
} }
}
}
stage('Build') {
when { allOf {
expression { return !PIPELINE_CONTROL.ci_skip }
} }
steps {
timeout(time: 10, unit: 'MINUTES') { script {
// copy test properties file
sh "cp resources/testProfileData.example.ts resources/testProfileData.ts"
sh "npm run build"
} }
}
}
stage('Test') {
when { allOf {
expression { return !PIPELINE_CONTROL.ci_skip }
expression { return !params.SKIP_TEST }
} }
steps {
timeout(time: 10, unit: 'MINUTES') { script {
sh "npm run test"
} }
}
}
stage('Audit') {
when { allOf {
expression { return !PIPELINE_CONTROL.ci_skip }
expression { return !params.SKIP_AUDIT }
} }
steps {
timeout(time: 10, unit: 'MINUTES') { script {
sh "npm audit"
} }
}
}
stage("Publish") {
when { allOf {
expression { return !PIPELINE_CONTROL.ci_skip }
expression { return BRANCH_NAME == MASTER_BRANCH }
expression { return !params.SKIP_PUBLISH }
} }
steps {
timeout(time: 10, unit: 'MINUTES') { script {
def vscodePackageJson = readJSON file: "package.json"
def extensionMetadata = sh(returnStdout: true, script: "npx vsce show ${vscodePackageJson.publisher}.${vscodePackageJson.name} --json").trim()
def extensionInfo = readJSON text: extensionMetadata
if (extensionInfo.versions[0].version == vscodePackageJson.version) {
echo "No new version to publish at this time (${vscodePackageJson.version})"
} else {
echo "Publishing version ${vscodePackageJson.version} since it's different from ${extensionInfo.versions[0].version}"
withCredentials([string(credentialsId: PUBLISH_TOKEN, variable: 'TOKEN')]) {
sh "npx vsce publish -p $TOKEN"
}
sh "git config --global user.name \"zowe-robot\""
sh "git config --global user.email \"[email protected]\""
sh "git tag v${vscodePackageJson.version}"
withCredentials([usernamePassword(credentialsId: ZOWE_ROBOT_TOKEN, usernameVariable: 'USERNAME', passwordVariable: 'TOKEN')]) {
sh "git push --tags https://$TOKEN:[email protected]/zowe/vscode-extension-for-zowe.git"
}
}
} }
}
}
}
post { always { script {
def buildStatus = currentBuild.currentResult
def recipients = params.RECIPIENTS_LIST != '' ? params.RECIPIENTS_LIST : "${MASTER_RECIPIENTS_LIST}"
def subjectTitle = "VSCode Extension Deployment"
def details = "${subjectTitle}"
if (!PIPELINE_CONTROL.ci_skip) {
try {
try {
sh("cp -rf /home/jenkins/.npm/_logs deploy-log")
} catch(e) {}
archiveArtifacts allowEmptyArchive: true, artifacts: 'deploy-log/*.log'
if (PIPELINE_CONTROL.ci_skip) {
currentBuild.result = "SUCCESS"
} else {
if (buildStatus.equals("SUCCESS")) {
details = "${details} succeded."
} else {
details = "${details} failed.\n\nPlease investigate build ${currentBuild.number}"
}
details = "${details}\n\nBuild result: ${currentBuild.absoluteUrl}"
emailext(to: recipients, subject: "[${buildStatus}] ${subjectTitle}", body: details)
}
} catch (e) {
echo "Experienced an error sending an email for a ${buildStatus} build"
currentBuild.result = buildStatus
echo "${details}"
}
}
} } }
}