forked from dynatrace-sockshop/front-end
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
123 lines (121 loc) · 3 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
@Library('dynatrace@master') _
def tagMatchRules = [
[
meTypes: [
[meType: 'SERVICE']
],
tags : [
[context: 'CONTEXTLESS', key: 'app', value: 'front-end'],
[context: 'CONTEXTLESS', key: 'environment', value: 'dev']
]
]
]
pipeline {
agent {
label 'nodejs'
}
environment {
APP_NAME = "front-end"
ARTEFACT_ID = "sockshop/" + "${env.APP_NAME}"
VERSION = readFile('version').trim()
TAG = "${env.DOCKER_REGISTRY_URL}:5000/library/${env.ARTEFACT_ID}"
TAG_DEV = "${env.TAG}-${env.VERSION}-${env.BUILD_NUMBER}"
TAG_STAGING = "${env.TAG}-${env.VERSION}"
}
stages {
stage('Node build') {
steps {
checkout scm
container('nodejs') {
sh 'npm install'
}
}
}
stage('Docker build') {
when {
expression {
return env.BRANCH_NAME ==~ 'release/.*' || env.BRANCH_NAME ==~'master'
}
}
steps {
container('docker') {
sh "docker build -t ${env.TAG_DEV} ."
}
}
}
stage('Docker push to registry') {
when {
expression {
return env.BRANCH_NAME ==~ 'release/.*' || env.BRANCH_NAME ==~'master'
}
}
steps {
container('docker') {
sh "docker push ${env.TAG_DEV}"
}
}
}
stage('Deploy to dev namespace') {
when {
expression {
return env.BRANCH_NAME ==~ 'release/.*' || env.BRANCH_NAME ==~'master'
}
}
steps {
container('kubectl') {
sh "sed -i 's#image: .*#image: ${env.TAG_DEV}#' manifest/front-end.yml"
sh "kubectl -n dev apply -f manifest/front-end.yml"
}
}
}
stage('DT Deploy Event') {
when {
expression {
return env.BRANCH_NAME ==~ 'release/.*' || env.BRANCH_NAME ==~'master'
}
}
steps {
container("curl") {
script {
def status = pushDynatraceDeploymentEvent (
tagRule : tagMatchRules,
customProperties : [
[key: 'Jenkins Build Number', value: "${env.BUILD_ID}"],
[key: 'Git commit', value: "${env.GIT_COMMIT}"]
]
)
}
}
}
}
stage('Mark artifact for staging namespace') {
when {
expression {
return env.BRANCH_NAME ==~ 'release/.*'
}
}
steps {
container('docker'){
sh "docker tag ${env.TAG_DEV} ${env.TAG_STAGING}"
sh "docker push ${env.TAG_STAGING}"
}
}
}
stage('Deploy to staging') {
when {
beforeAgent true
expression {
return env.BRANCH_NAME ==~ 'release/.*'
}
}
steps {
build job: "k8s-deploy-staging",
parameters: [
string(name: 'APP_NAME', value: "${env.APP_NAME}"),
string(name: 'TAG_STAGING', value: "${env.TAG_STAGING}"),
string(name: 'VERSION', value: "${env.VERSION}")
]
}
}
}
}