-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
94 lines (90 loc) · 2.9 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
/*
* This is a vanilla Jenkins pipeline that relies on the Jenkins kubernetes plugin to dynamically provision agents for
* the build containers.
*
* The individual containers are defined in the `jenkins-pod-template.yaml` and the containers are referenced by name
* in the `container()` blocks. The underlying pod definition expects certain kube Secrets and ConfigMap objects to
* have been created in order for the Pod to run. See `jenkins-pod-template.yaml` for more information.
*
* The cloudName variable is set dynamically based on the existance/value of env.CLOUD_NAME which allows this pipeline
* to run in both Kubernetes and OpenShift environments.
*/
def buildAgentName(String jobName, String buildNumber) {
if (jobName.length() > 55) {
jobName = jobName.substring(0, 55);
}
return "a.${jobName}.${buildNumber}".replace('_', '-').replace('/', '-').replace('-.', '.');
}
def buildLabel = buildAgentName(env.JOB_NAME, env.BUILD_NUMBER);
def namespace = env.NAMESPACE ?: "dev"
def cloudName = env.CLOUD_NAME == "openshift" ? "openshift" : "kubernetes"
def workingDir = env.CLOUD_NAME == "openshift" ? "/home/jenkins" : "/home/jenkins/agent"
podTemplate(
label: buildLabel,
cloud: cloudName,
yaml: """
apiVersion: v1
kind: Pod
spec:
serviceAccountName: jenkins
containers:
- name: node
image: node:11-stretch
tty: true
command: ["/bin/bash"]
workingDir: ${workingDir}
envFrom:
- configMapRef:
name: pactbroker-config
optional: true
- configMapRef:
name: sonarqube-config
optional: true
- secretRef:
name: sonarqube-access
optional: true
env:
- name: HOME
value: ${workingDir}
"""
) {
node(buildLabel) {
container(name: 'node', shell: '/bin/bash') {
checkout scm
stage('Install') {
sh '''#!/bin/bash
npm install
'''
}
stage('Build') {
sh '''#!/bin/bash
npm run build
'''
}
stage('Git init') {
sh '''#!/bin/bash
git config --global user.email "jenkins@ibm.com"
git config --global user.name "Jenkins Pipeline"
'''
}
stage('Checkout gh-pages') {
sh '''#!/bin/bash
git remote -v
git checkout -b test-pages origin/test-pages
'''
}
stage('Copy files') {
sh '''#!/bin/bash
cp -R ./public/* .
'''
}
stage('Push changes') {
sh '''#!/bin/bash
git add .
git commit -m "Pipeline updates"
git push
'''
}
}
}
}