This repository has been archived by the owner on Jun 5, 2023. It is now read-only.
forked from zowe/docs-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
151 lines (133 loc) · 4.61 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
#!groovy
/**
* 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 IBM Corporation 2018
*/
def isPullRequest = env.BRANCH_NAME.startsWith('PR-')
def slackChannel = '#test-build-notify'
def allowPublishing = env.BRANCH_NAME == 'master'
def opts = []
// keep last 20 builds for regular branches, no keep for pull requests
opts.push(buildDiscarder(logRotator(numToKeepStr: (isPullRequest ? '' : '20'))))
// disable concurrent build
opts.push(disableConcurrentBuilds())
// define custom build parameters
def customParameters = []
// >>>>>>>> parameters to control pipeline behavior
customParameters.push(booleanParam(
name: 'RUN_PUBLISH',
description: 'If run the piublish step.',
defaultValue: true
))
customParameters.push(string(
name: 'PUBLISH_BRANCH',
description: 'Target branch to publish',
defaultValue: 'gh-pages',
trim: true,
required: true
))
customParameters.push(credentials(
name: 'GITHUB_CREDENTIALS',
description: 'Github user credentials',
credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl',
defaultValue: 'zowe-robot-github',
required: true
))
customParameters.push(string(
name: 'GITHUB_USER_EMAIL',
description: 'github user email',
defaultValue: 'zowe.robot@gmail.com',
trim: true,
required: true
))
customParameters.push(string(
name: 'GITHUB_USER_NAME',
description: 'github user name',
defaultValue: 'Zowe Robot',
trim: true,
required: true
))
opts.push(parameters(customParameters))
// set build properties
properties(opts)
node ('ibm-jenkins-slave-nvm') {
currentBuild.result = 'SUCCESS'
try {
stage('checkout') {
// checkout source code
checkout scm
// check if it's pull request
echo "Current branch is ${env.BRANCH_NAME}"
if (isPullRequest) {
echo "This is a pull request"
}
}
stage('build') {
ansiColor('xterm') {
sh 'npm install'
sh 'npm run docs:build'
}
}
stage('test') {
ansiColor('xterm') {
// list all files generated
sh 'find docs/.vuepress/dist'
// check broken links
sh 'npm run test:links'
}
}
utils.conditionalStage('publish', allowPublishing && params.RUN_PUBLISH) {
ansiColor('xterm') {
withCredentials([usernamePassword(
credentialsId: params.GITHUB_CREDENTIALS,
passwordVariable: 'GIT_PASSWORD',
usernameVariable: 'GIT_USERNAME'
)]) {
sh """
cd docs/.vuepress/dist
git config --global user.email \"${params.GITHUB_USER_EMAIL}\"
git config --global user.name \"${params.GITHUB_USER_NAME}\"
git init
git add -A
git commit -m \"deploy from ${env.JOB_NAME}#${env.BUILD_NUMBER}\"
git push -f https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/zowe/docs-site.git master:${params.PUBLISH_BRANCH}
"""
}
}
}
stage('done') {
// send out notification
// slackSend channel: slackChannel,
// color: 'good',
// message: "Job \"${env.JOB_NAME}\" build #${env.BUILD_NUMBER} succeeded.\n\nCheck detail: ${env.BUILD_URL}"
emailext body: "Job \"${env.JOB_NAME}\" build #${env.BUILD_NUMBER} succeeded.\n\nCheck detail: ${env.BUILD_URL}" ,
subject: "[Jenkins] Job \"${env.JOB_NAME}\" build #${env.BUILD_NUMBER} succeeded",
recipientProviders: [
[$class: 'RequesterRecipientProvider'],
[$class: 'CulpritsRecipientProvider'],
[$class: 'DevelopersRecipientProvider'],
[$class: 'UpstreamComitterRecipientProvider']
]
}
} catch (err) {
currentBuild.result = 'FAILURE'
// catch all failures to send out notification
// slackSend channel: slackChannel,
// color: 'warning',
// message: "Job \"${env.JOB_NAME}\" build #${env.BUILD_NUMBER} failed.\n\nError: ${err}\n\nCheck detail: ${env.BUILD_URL}"
emailext body: "Job \"${env.JOB_NAME}\" build #${env.BUILD_NUMBER} failed.\n\nError: ${err}\n\nCheck detail: ${env.BUILD_URL}" ,
subject: "[Jenkins] Job \"${env.JOB_NAME}\" build #${env.BUILD_NUMBER} failed",
recipientProviders: [
[$class: 'RequesterRecipientProvider'],
[$class: 'CulpritsRecipientProvider'],
[$class: 'DevelopersRecipientProvider'],
[$class: 'UpstreamComitterRecipientProvider']
]
throw err
}
}