This repository has been archived by the owner on Jan 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathJenkinsfile
170 lines (142 loc) · 5.08 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
#!/usr/bin/env groovy
def lintStages(buildData, params) {
if (buildData.isPrJob) {
stage('commitlint') {
if (params.RUN_LINT) {
sh 'yarn commitlint --from=origin/$CHANGE_TARGET'
}
}
}
stage('eslint') {
if (params.RUN_LINT) {
sh 'yarn lint'
}
}
}
def unitTestsStage(buildData, params) {
stage('unit tests') {
if (params.RUN_UNIT_TESTS) {
sh '''
yarn test
'''
}
}
}
def buildJsStage(buildData, params, env) {
stage('build') {
if (!buildData.isPrJob && params.PUBLISH_A_RELEASE) {
withVaultEnv([["npm/confluent_npm", "token", "NPM_TOKEN"],
["github/confluent_jenkins", "access_token", "GH_TOKEN"]]) {
sh "echo '//registry.npmjs.org/:_authToken=${env.NPM_TOKEN}' >> \$HOME/.npmrc"
sh "yarn release --force-publish --create-release=github --yes"
}
}
}
}
node('docker-debian-10-node') {
def buildData = [
buildStatus: 'Failure',
buildJsStatus: 'Pending',
isMasterBranch: env.BRANCH_NAME == 'master',
isPrJob: !(env.JOB_NAME.startsWith('confluentinc/') || env.JOB_NAME.startsWith('confluentinc-post/')),
revision: '',
]
properties([
buildDiscarder(
logRotator(
artifactDaysToKeepStr: '',
artifactNumToKeepStr: '',
daysToKeepStr: '7',
numToKeepStr: ''
)
),
parameters([
booleanParam(name: 'RUN_LINT',
defaultValue: true,
description: "Turn the lint stage on"),
booleanParam(name: 'RUN_UNIT_TESTS',
defaultValue: true,
description: "Turn the unit tests stage on"),
booleanParam(name: 'PUBLISH_A_RELEASE',
defaultValue: false,
description: "${env.BRANCH_NAME} branch only - publishes a release, generates a git tag and updates the changelogs"),
])
])
try {
stage('checkout') {
echo sh(returnStdout: true, script: 'env')
if (!buildData.isPrJob && params.PUBLISH_A_RELEASE) {
slackNotify(
status: 'Started',
channel: '#ksql-fe',
always: true
)
checkout scm: [
$class: 'GitSCM',
userRemoteConfigs: [
[
credentialsId: 'ConfluentJenkins Github SSH Key',
url: '[email protected]:confluentinc/ksqldb-graphql.git'
]
]
]
configureGitSSH("github/confluent_jenkins", "private_key")
sh 'git config --global user.email "[email protected]"'
sh 'git config --global user.name "Confluent Jenkins Bot"'
sh 'git checkout $BRANCH_NAME'
sh 'git pull origin $BRANCH_NAME --force'
} else {
checkout scm
}
buildData.revision = sh(returnStdout: true, script: 'git rev-parse --short=7 HEAD').trim()
}
currentBuild.displayName = "#${env.BUILD_NUMBER} ${buildData.revision}"
if (params.PUBLISH_A_RELEASE) {
currentBuild.displayName = "${currentBuild.displayName} Publishing a ksqldb-graphql release"
}
stage('install') {
sh '''
yarn config list
yarn config current
yarn in
'''
}
def pStages = ['linting', 'unit tests', 'buildJs'].collectEntries {stageLabel -> [stageLabel, {
if (stageLabel == 'linting') {
lintStages(buildData, params)
}
if (stageLabel == 'unit tests') {
unitTestsStage(buildData, params)
}
if (stageLabel == 'buildJs') {
try {
buildJsStage(buildData, params, env)
} catch (Exception e){
buildData.buildJsStatus = 'Failure'
throw e
}
}
}]}
pStages.failFast = true;
parallel(pStages)
// at this point the build is gauranteed ok due to failFast
if (buildData.buildStatus != 'Unstable') {
buildData.buildStatus = 'Success'
}
} catch (hudson.AbortException e) {
// Exit code 143 = SIGTERM from user abort.
if (e.message.contains('script returned exit code 143')) {
buildData.buildStatus = 'Aborted'
}
throw e
} finally {
if (!buildData.isPrJob && params.PUBLISH_A_RELEASE) {
slackNotify(
status: buildData.buildStatus,
detail: "New release published: https://github.com/confluentinc/ksqldb-graphql/releases",
channel: '#ksql-fe',
always: true
)
}
}
}