-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
157 lines (150 loc) · 5.99 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
def dockerHubRepo = "icgcargo/workflow-docs"
def gitHubRepo = "icgc-argo/workflow-docs"
def chartVersion = "0.2.0"
def commit = "UNKNOWN"
def version = "UNKNOWN"
pipeline {
agent {
kubernetes {
label 'workflow-docs'
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: node
image: node:12.6.0
tty: true
- name: dind-daemon
image: docker:18.06-dind
securityContext:
privileged: true
volumeMounts:
- name: docker-graph-storage
mountPath: /var/lib/docker
- name: docker
image: docker:18-git
tty: true
env:
- name: DOCKER_HOST
value: tcp://localhost:2375
volumes:
- name: docker-graph-storage
emptyDir: {}
"""
}
}
stages {
stage('Prepare') {
steps {
script {
commit = sh(returnStdout: true, script: 'git describe --always').trim()
}
script {
version = sh(returnStdout: true, script: 'cat ./package.json | grep \\"version\\" | cut -d \':\' -f2 | sed -e \'s/"//\' -e \'s/",//\'').trim()
}
script {
sh "echo ${commit}"
sh "echo ${version}"
}
}
}
stage('Test') {
steps {
container('node') {
sh "npm ci"
sh "npm run test"
}
}
}
stage('Build edge') {
when {
branch "develop"
}
steps {
container('docker') {
withCredentials([usernamePassword(credentialsId:'argoDockerHub', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh 'docker login -u $USERNAME -p $PASSWORD'
}
// DNS error if --network is default
sh "docker build --network=host . -t ${dockerHubRepo}:edge -t ${dockerHubRepo}:${version}-${commit}"
sh "docker push ${dockerHubRepo}:${version}-${commit}"
sh "docker push ${dockerHubRepo}:edge"
}
}
}
stage('deploy to rdpc-collab-dev') {
when {
branch "develop"
}
steps {
build(job: "/provision/helm", parameters: [
[$class: 'StringParameterValue', name: 'AP_RDPC_ENV', value: 'dev' ],
[$class: 'StringParameterValue', name: 'AP_CHART_NAME', value: 'workflow-docs'],
[$class: 'StringParameterValue', name: 'AP_RELEASE_NAME', value: 'docs'],
[$class: 'StringParameterValue', name: 'AP_HELM_CHART_VERSION', value: "${chartVersion}"],
[$class: 'StringParameterValue', name: 'AP_ARGS_LINE', value: "--set-string image.tag=${version}-${commit}" ]
])
}
}
stage('Build latest') {
when {
branch "master"
}
steps {
container('docker') {
withCredentials([usernamePassword(credentialsId: 'argoGithub', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh "git tag ${version}"
sh "git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/${gitHubRepo} --tags"
}
withCredentials([usernamePassword(credentialsId:'argoDockerHub', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh 'docker login -u $USERNAME -p $PASSWORD'
}
sh "docker build --network=host -f Dockerfile . -t ${dockerHubRepo}:latest -t ${dockerHubRepo}:${version}"
sh "docker push ${dockerHubRepo}:${version}"
sh "docker push ${dockerHubRepo}:latest"
}
}
}
stage('deploy to rdpc-collab-qa') {
when {
branch "master"
}
steps {
build(job: "/provision/helm", parameters: [
[$class: 'StringParameterValue', name: 'AP_RDPC_ENV', value: 'qa' ],
[$class: 'StringParameterValue', name: 'AP_CHART_NAME', value: 'workflow-docs'],
[$class: 'StringParameterValue', name: 'AP_RELEASE_NAME', value: 'docs'],
[$class: 'StringParameterValue', name: 'AP_HELM_CHART_VERSION', value: "${chartVersion}"],
[$class: 'StringParameterValue', name: 'AP_ARGS_LINE', value: "--set-string image.tag=${version}" ]
])
}
}
}
post {
unsuccessful {
// i used node container since it has curl already
container("node") {
script {
if (env.BRANCH_NAME == "master" || env.BRANCH_NAME == "develop") {
withCredentials([string(credentialsId: 'JenkinsFailuresSlackChannelURL', variable: 'JenkinsFailuresSlackChannelURL')]) {
sh "curl -X POST -H 'Content-type: application/json' --data '{\"text\":\"Build Failed: ${env.JOB_NAME} [${env.BUILD_NUMBER}] (${env.BUILD_URL}) \"}' ${JenkinsFailuresSlackChannelURL}"
}
}
}
}
}
fixed {
// i used node container since it has curl already
container("node") {
script {
if (env.BRANCH_NAME == "master" || env.BRANCH_NAME == "develop") {
withCredentials([string(credentialsId: 'JenkinsFailuresSlackChannelURL', variable: 'JenkinsFailuresSlackChannelURL')]) {
sh "curl -X POST -H 'Content-type: application/json' --data '{\"text\":\"Build Fixed: ${env.JOB_NAME} [${env.BUILD_NUMBER}] (${env.BUILD_URL}) \"}' ${JenkinsFailuresSlackChannelURL}"
}
}
}
}
}
}
}