forked from contiamo/operational-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
114 lines (111 loc) · 4.4 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
#!/usr/bin/env groovy
def lib = new contiamo.Methods()
lib.setEnvVars()
def label = env.JenkinsSlaveName
echo "Slave pod name: "+label
/////// List all the downstream projects here:///////
def downstreamProjects = ["labs-ui","pantheon-ui"]
////////////////////////////////////////////////////
def triggerJob(job,branch){
println "Triggering ${job}/${branch}"
build job: "../${job}/${branch}", wait: false
}
def npmLogin(registry,user,pass,email){
sh """
#!/bin/bash
sed s/REGISTRY_PLACEHOLDER/${registry}/g -i /usr/local/bin/npm-login.sh
/usr/local/bin/npm-login.sh ${user} ${pass} ${email}
npm config set //$registry/:always-auth=true
"""
}
def npmPublish(tag,registry){
sh """
#!/bin/bash
npm whoami --registry https://${registry}
npm version \$(npm show . version)-\$(git rev-parse --short HEAD) --no-git-tag-version --registry https://${registry} --unsafe-perm
(npm publish --tag next --registry https://${registry} && node ./lambdas/notify-slack-on-publish-next.js \$(npm show . version)-\$(git rev-parse --short HEAD)) || echo "Publish failed, possibly because the SHA is the same. Continuing..."
"""
}
def buildWebsite(dir,command){
sh "cd ${dir} && yarn ${command} && cd -"
}
podTemplate(cloud: "${env.K8sCloud}", label: label, serviceAccount: "jenkins", containers: [
containerTemplate(name: 'node', image: "${env.GcrPrefix}/node:10.0.0-v0.5", ttyEnabled: true, nodeSelector: "group=highmem", privileged: true),
containerTemplate(name: 'build-utils', image: "${env.GcrPrefix}/build-utils:0.0.8", ttyEnabled: true, nodeSelector: "group=highmem", privileged: true)
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
hostPathVolume(mountPath: '/tmp', hostPath: '/tmp'),
secretVolume(secretName: 'jenkins-git-credentials', mountPath: '/home/jenkins/git'),
],
envVars: [
envVar(key: 'GIT_AUTHOR_EMAIL', value: '[email protected]'),
envVar(key: 'GIT_AUTHOR_NAME', value: 'jenkins-x-bot'),
envVar(key: 'GIT_COMMITTER_EMAIL', value: '[email protected]'),
envVar(key: 'GIT_COMMITTER_NAME', value: 'jenkins-x-bot'),
envVar(key: 'JENKINS_URL', value: 'http://jenkins:8080'),
envVar(key: 'XDG_CONFIG_HOME', value: '/home/jenkins'),
secretEnvVar(key: 'NPM_PASS', secretName: 'npm-registry-creds', secretKey: 'password'),
secretEnvVar(key: 'NPM_USER', secretName: 'npm-registry-creds', secretKey: 'username')
]
)
{
timestamps {
ansiColor('xterm') {
node(label){
try {
stage('Git Checkout'){
lib.gitCheckout()
}
container('node') {
stage("Initialize"){
sh "node -v && npm -v"
}
stage ('YARN Install'){
try {
sh "yarn install"
} catch(e) {
error("Failed while running npm install. Error: ${e}")
}
}
stage ('Test'){
try {
sh "yarn ci"
} catch(e) {
error("Failed while running npm ci. Error: ${e}")
}
}
env.NpmRegistry = "registry.npmjs.org"
if (env.BranchLower == "master") {
stage ('NPM Publish Next Tag') {
env.NpmRegistry = "registry.npmjs.org"
npmLogin(env.NpmRegistry,"\${NPM_USER}","\${NPM_PASS}",env.NpmEmail)
try {
npmPublish("next",env.NpmRegistry)
} catch(e) {
println("Error publishing artefacts. Error: ${e}. Trying again...")
npmPublish("next",env.NpmRegistry)
}
}
lib.haveAword('yellow',"Triggering downstream build")
stage('Trigger Contiamo UI'){
build(job: '../contiamo-ui/master', wait: false, parameters: [
[$class: 'StringParameterValue', name: 'UPDATE', value: "operational-ui" ]
])
}
}
}
} catch(Exception e) {
container('build-utils'){
if (env.BranchLower == "master") {
lib.postToSlackV3(colour: "danger", channel: "frontend", title: "${env.JobNameWithoutBranch} build failed", message: "Build URL: ${env.BUILD_URL}/console")
}
}
errorMessage = e.toString()
println(errorMessage)
error("Pipeline failed")
}
}
}
}
}