forked from scm-manager/website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
112 lines (90 loc) · 3.17 KB
/
Jenkinsfile
File metadata and controls
112 lines (90 loc) · 3.17 KB
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
#!groovy
node('docker') {
def version = 'UNKNOWN'
properties([
// Keep only the last 10 build to preserve space
buildDiscarder(logRotator(numToKeepStr: '10')),
disableConcurrentBuilds()
])
timeout(activity: true, time: 30, unit: 'MINUTES') {
catchError {
stage('Checkout') {
checkout scm
// TODO staging and prod use the same image and version scheme?
def commitHashShort = sh(returnStdout: true, script: 'git rev-parse --short HEAD')
version = "${new Date().format('yyyyMMddHHmm')}-${commitHashShort}".trim()
}
stage('Apply Cache') {
sh 'rm -rf public .cache website.tar.gz || true'
googleStorageDownload bucketUri: 'gs://scm-manager/cache/website.tar.gz', credentialsId: 'ces-demo-instances', localDirectory: '.'
sh 'tar xfz cache/website.tar.gz'
sh 'rm -rf cache'
}
stage('Dependencies') {
withNode {
sh "yarn install"
}
}
stage('Collect Content') {
withNode {
withCredentials([usernamePassword(credentialsId: 'cesmarvin-github', passwordVariable: 'GITHUB_API_TOKEN', usernameVariable: 'GITHUB_ACCOUNT')]) {
sh "yarn run collect-content"
}
}
}
stage('Build') {
def siteUrl = env.BRANCH_NAME == 'staging' ? 'https://staging-website.scm-manager.org' : 'https://scm-manager.org'
withNode {
withEnv(["SITE_URL=${siteUrl}"]) {
sh "yarn run build"
}
}
}
stage('Image') {
def image = docker.build "scmmanager/website:${version}"
docker.withRegistry('', 'hub.docker.com-cesmarvin') {
image.push()
}
}
if (env.BRANCH_NAME == 'staging') {
stage('Staging Deployment') {
withHelm {
sh "helm upgrade --install --values=deployment/staging.yml --set image.tag=${version} staging-website deployment/website"
}
}
} else if (env.BRANCH_NAME == 'master') {
stage('Deployment') {
withHelm {
sh "helm upgrade --install --set image.tag=${version} website deployment/website"
}
}
stage('Trigger API Build') {
build job: 'scm-manager-github/plugin-center-api/master', wait: false
}
stage('Update Cache') {
sh "tar cfz website.tar.gz public .cache"
googleStorageUpload bucket: 'gs://scm-manager/cache', credentialsId: 'ces-operations-internal', pattern: 'website.tar.gz'
}
}
}
if (currentBuild.currentResult == 'FAILURE') {
mail to: "scm-team@cloudogu.com",
subject: "${JOB_NAME} - Build #${BUILD_NUMBER} - ${currentBuild.currentResult}!",
body: "Check console output at ${BUILD_URL} to view the results."
}
}
}
void withNode(Closure closure) {
docker.image('scmmanager/node-build:12.16.3').inside {
withEnv(["HOME=${env.WORKSPACE}"]) {
closure.call()
}
}
}
void withHelm(Closure closure) {
docker.image('lachlanevenson/k8s-helm:v3.2.1').inside('--entrypoint=""') {
withCredentials([file(credentialsId: 'helm-client-scm-manager', variable: 'KUBECONFIG')]) {
closure.call()
}
}
}