forked from zowe/zowe-explorer-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
178 lines (149 loc) · 7.69 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
174
175
176
177
178
/*
* 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.
*
*/
@Library('shared-pipelines') import org.zowe.pipelines.nodejs.NodeJSPipeline
node('ca-jenkins-agent') {
// This is the product name used by the build machine to store information about the builds
def PRODUCT_NAME = "Zowe Explorer"
// This is the what should be considered the master branch (for deployment purposes)
def MASTER_BRANCH = "master"
// Artifactory Details
def ARTIFACTORY_CREDENTIALS_ID = "zowe.jfrog.io"
def ARTIFACTORY_UPLOAD_URL = "https://zowe.jfrog.io/zowe/libs-release-local/org/zowe/vscode"
// Other Credential IDs
def PUBLISH_TOKEN = "vsce-publish-key"
def ZOWE_ROBOT_TOKEN = "zowe-robot-github"
def CODECOV_CREDENTIALS_ID = 'CODECOV_ZOWE_VSCODE'
// Testing related variables
def TEST_ROOT = "results"
def UNIT_TEST_ROOT = "$TEST_ROOT/unit"
def UNIT_JUNIT_OUTPUT = "$UNIT_TEST_ROOT/junit.xml"
def SYSTEM_TEST_ROOT = "$TEST_ROOT/system"
def SYSTEM_JUNIT_OUTPUT = "$SYSTEM_TEST_ROOT/junit.xml"
// Initialize the pipeline
def pipeline = new NodeJSPipeline(this)
// Build admins, users that can approve the build and receieve emails for all protected branch builds.
pipeline.admins.add("stonecc", "zfernand0", "mikebauerca")
// Comma-separated list of emails that should receive notifications about every build on every branch : )
// There are plans to send branch-specific emails to the developers in questions. For more information please look for emailProviders
pipeline.emailList = "[email protected]"
// Protected branch property definitions
pipeline.protectedBranches.addMap([
[name: "master", tag: "latest", dependencies: ["@zowe/cli": "zowe-v1-lts"]]
])
// Git configuration information
pipeline.gitConfig = [
email: '[email protected]',
credentialsId: 'zowe-robot-github'
]
// Initialize the pipeline library, should create 5 steps
pipeline.setup()
// Lint the source code
pipeline.lint()
// Build the application
pipeline.build(
timeout: [ time: 10, unit: 'MINUTES' ],
operation: {
// Create a dummy TestProfileData in order to build the source code. See issue #556
sh "cp resources/testProfileData.example.ts resources/testProfileData.ts"
sh "npm run build"
}
)
// Perform Unit Tests and capture the results
pipeline.test(
name: "Unit",
operation: {
sh "npm run test:unit"
},
timeout: [ time: 10, unit: 'MINUTES' ],
environment: [
JEST_JUNIT_OUTPUT: UNIT_JUNIT_OUTPUT,
JEST_SUIT_NAME: "Unit Tests",
JEST_JUNIT_ANCESTOR_SEPARATOR: " > ",
JEST_JUNIT_CLASSNAME: "Unit.{classname}",
JEST_JUNIT_TITLE: "{title}",
JEST_STARE_RESULT_DIR: "${UNIT_TEST_ROOT}/jest-stare",
JEST_STARE_RESULT_HTML: "index.html"
],
testResults: [dir: "${UNIT_TEST_ROOT}/jest-stare", files: "index.html", name: "${PRODUCT_NAME} - Unit Test Report"],
coverageResults: [dir: "${UNIT_TEST_ROOT}/coverage/lcov-report", files: "index.html", name: "${PRODUCT_NAME} - Unit Test Coverage Report"],
junitOutput: UNIT_JUNIT_OUTPUT,
cobertura: [
coberturaReportFile: "${UNIT_TEST_ROOT}/coverage/cobertura-coverage.xml",
maxNumberOfBuilds: 20,
sourceEncoding: 'ASCII'
]
)
// Upload Reports to Codecov. This may be replaced with Sonar Cloud in the near future. See #473
pipeline.createStage(
name: "Codecov",
stage: {
withCredentials([usernamePassword(credentialsId: CODECOV_CREDENTIALS_ID, usernameVariable: 'CODECOV_USERNAME', passwordVariable: 'CODECOV_TOKEN')]) {
sh "curl -s https://codecov.io/bash | bash -s"
}
}
)
// Check for Vulnerabilities
pipeline.checkVulnerabilities()
// Publish a new version of the extensions if needed
pipeline.createStage(
name: "Publish",
shouldExecute: { env.BRANCH_NAME == MASTER_BRANCH },
timeout: [ time: 10, unit: 'MINUTES' ],
stage: {
// Gather details about the extension for comparison
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
// Check if we need to publish a new version
if (extensionInfo.versions[0].version == vscodePackageJson.version) {
echo "No new version to publish at this time (${vscodePackageJson.version})"
// Will stop here if there wasn't a requirement to publish anything
return;
}
// Publish new version
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"
}
// Prepare GitHub Release
def version = "v${vscodePackageJson.version}"
def versionName = "vscode-extension-for-zowe-v${vscodePackageJson.version}"
sh "npx vsce package -o ${versionName}.vsix"
// Upload Final VSIX to Artifactory
withCredentials([usernamePassword(credentialsId: ARTIFACTORY_CREDENTIALS_ID, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
def uploadUrlArtifactory = "${ARTIFACTORY_UPLOAD_URL}/${versionName}.vsix"
sh "curl -u ${USERNAME}:${PASSWORD} --data-binary \"@${versionName}.vsix\" -H \"Content-Type: application/octet-stream\" -X PUT ${uploadUrlArtifactory}"
}
// Create the GitHub Release
withCredentials([usernamePassword(credentialsId: ZOWE_ROBOT_TOKEN, usernameVariable: 'USERNAME', passwordVariable: 'TOKEN')]) {
sh "git push --tags https://$TOKEN:[email protected]/zowe/vscode-extension-for-zowe.git"
// Grab changelog, convert to unix line endings, get changes under current version, publish release to github with changes in body
def releaseVersion = sh(returnStdout: true, script: "echo ${version} | cut -c 2-").trim()
sh "npm install ssp-dos2unix"
sh "node ./scripts/d2uChangelog.js"
def releaseChanges = sh(returnStdout: true, script: "awk -v ver=${releaseVersion} '/## / {if (p) { exit }; if (\$2 ~ ver) { p=1; next} } p && NF' CHANGELOG.md | sed -z \"s/'/'\\\\\\''/g\" | sed -z 's/\"/\\\"/g' | sed -z 's/\\n/\\\\n/g'").trim()
// Gather details about the GitHub APIs used to publish a release
def releaseAPI = "repos/zowe/vscode-extension-for-zowe/releases"
def releaseDetails = "{\"tag_name\":\"$version\",\"target_commitish\":\"master\",\"name\":\"$version\",\"body\":\"$releaseChanges\",\"draft\":false,\"prerelease\":false}"
def releaseUrl = "https://$TOKEN:[email protected]/${releaseAPI}"
// Create the release
def releaseCreated = sh(returnStdout: true, script: "curl -H \"Content-Type: application/json\" -X POST -d '${releaseDetails}' ${releaseUrl}").trim()
def releaseParsed = readJSON text: releaseCreated
// Upload vsix to the release that was just created
def uploadUrl = "https://$TOKEN:[email protected]/${releaseAPI}/${releaseParsed.id}/assets?name=${versionName}.vsix"
sh "curl -X POST --data-binary @${versionName}.vsix -H \"Content-Type: application/octet-stream\" ${uploadUrl}"
}
}
)
// Once called, no stages can be added and all added stages will be executed.
// On completion appropriate emails will be sent out by the shared library.
pipeline.end()
}