forked from nuxeo/jx-webui-env
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
152 lines (141 loc) · 5.21 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
/*
* (C) Copyright 2019 Nuxeo (http://nuxeo.com/) and others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Contributors:
* Antoine Taillefer <ataillefer@nuxeo.com>
* Nelson Silva <nsilva@nuxeo.com>
*/
properties([
[$class: 'GithubProjectProperty', projectUrlStr: 'https://github.com/nuxeo/jx-platform-env/'],
[$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', daysToKeepStr: '60', numToKeepStr: '60', artifactNumToKeepStr: '5']],
disableConcurrentBuilds(),
])
void setGitHubBuildStatus(String context, String message, String state) {
step([
$class: 'GitHubCommitStatusSetter',
reposSource: [$class: 'ManuallyEnteredRepositorySource', url: 'https://github.com/nuxeo/jx-platform-env'],
contextSource: [$class: 'ManuallyEnteredCommitContextSource', context: context],
statusResultSource: [$class: 'ConditionalStatusResultSource', results: [[$class: 'AnyBuildResult', message: message, state: state]]],
])
}
pipeline {
agent {
label 'jenkins-jx-base'
}
environment {
SERVICE_ACCOUNT = 'jenkins'
}
stages {
stage('Upgrade Jenkins X platform') {
steps {
setGitHubBuildStatus('upgrade', 'Upgrade Jenkins X platform', 'PENDING')
container('jx-base') {
echo "Upgrade Jenkins X platform"
script {
// get the existing docker registry auth
def dockerAuth = sh(
script: "jx step credential -s jenkins-docker-cfg -k config.json | jq -r '..|.auth?'",
returnStdout: true
).trim();
// get the existing npm token
def npmToken = sh(
script: 'jx step credential -s jenkins-npm-token -k token',
returnStdout: true
).trim();
withEnv(["PUBLIC_DOCKER_REGISTRY_AUTH=${dockerAuth}", "NPM_TOKEN=${npmToken}"]) {
sh """
# initialize Helm without installing Tiller
helm init --client-only --service-account ${SERVICE_ACCOUNT}
# add local chart repository
helm repo add jenkins-x http://chartmuseum.jenkins-x.io
# replace env vars in values.yaml
envsubst < values.yaml > myvalues.yaml
# upgrade Jenkins X platform
jx upgrade platform --namespace=webui \
--local-cloud-environment \
--always-upgrade \
--cleanup-temp-files=true \
--batch-mode
"""
}
}
// force upgrade of jenkins pod
// https://jira.nuxeo.com/browse/NXBT-2889
script {
def jenkinsPod = sh(
script: "kubectl get pod -l app=jenkins -o jsonpath='{..metadata.name}'",
returnStdout: true
).trim()
if (jenkinsPod) {
// delete jenkins pod to recreate it
sh "kubectl delete pod ${jenkinsPod} --ignore-not-found=true"
echo "Deleted pod ${jenkinsPod} to recreate it."
} else {
echo "No jenkins pod found, won't recreate it."
}
}
}
}
post {
success {
setGitHubBuildStatus('upgrade', 'Upgrade Jenkins X platform', 'SUCCESS')
}
failure {
setGitHubBuildStatus('upgrade', 'Upgrade Jenkins X platform', 'FAILURE')
}
}
}
stage('Perform Git release') {
// TODO: skip if no changes since latest tag, to be able to manually run the pipeline on the master branch
// in order to revert a bad "jx upgrade platform" launched by a PR. This would run "jx upgrade platform"
// on the latest (stable) tag, aka master, without adding add an extra Git tag.
when {
branch 'master'
}
steps {
setGitHubBuildStatus('release', 'Release', 'PENDING')
container('jx-base') {
script {
VERSION = sh(returnStdout: true, script: 'jx-release-version')
}
withEnv(["VERSION=${VERSION}"]) {
sh """
# ensure we're not on a detached head
git checkout master
# create the Git credentials
jx step git credentials
git config credential.helper store
# Git tag
jx step tag -v ${VERSION}
# Git release
jx step changelog -v v${VERSION}
"""
}
}
}
post {
always {
step([$class: 'JiraIssueUpdater', issueSelector: [$class: 'DefaultIssueSelector'], scm: scm])
}
success {
setGitHubBuildStatus('release', 'Release', 'SUCCESS')
}
failure {
setGitHubBuildStatus('release', 'Release', 'FAILURE')
}
}
}
}
}