forked from navikt/fpsak-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfileFlytt
86 lines (71 loc) · 3.57 KB
/
JenkinsfileFlytt
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
import no.nav.jenkins.*
pipeline {
agent {
node {
label 'DOCKER2'
}
}
parameters {
string(defaultValue: "t4", description: 'Fra Miljø*', name: 'fra')
string(defaultValue: '', description: 'Til Miljø*', name: 'til')
}
stages {
stage('Promoter Til Miljø') {
steps {
script {
dir ('k8s') {
def naisNamespace
def version
def naisContext = (fra == "p") ? 'prod-fss' : 'preprod-fss'
sh "k config use-context ${naisContext}"
version = sh(
script: "k get pods -n\${fra} -l app=fpsak-frontend -o jsonpath='{.items[*].spec.containers[*].image}' | awk '{print \$1;}' | rev | cut -d: -f1 | rev",
returnStdout: true
).trim()
if (til == "p") {
naisNamespace = "default"
naisContext = "prod-fss"
} else {
naisNamespace = til
naisContext = "preprod-fss"
}
String msgColor = "#077040"
sh "k config use-context ${naisContext}"
def props = readProperties interpolate: true, file: "application.${til}.variabler.properties"
def value = "s/{{version}}/${version}/g"
props.each{ k,v -> value=value+";s%{{$k}}%$v%g" }
sh "sed \'$value\' app.yaml | k apply -f -"
slackInfo("Deploy av *fpsak-frontend*:" + version + " til *" + til + '*')
def exitCode=sh returnStatus: true, script: "k rollout status -n${naisNamespace} deployment/fpsak-frontend"
echo "exit code is $exitCode"
if(exitCode == 0) {
def veraPayload = "{\"environment\": \"${til}\",\"application\": \"fpsak-frontend\",\"version\": \"${version}\",\"deployedBy\": \"Jenkins\"}"
def response = httpRequest([
url : "https://vera.adeo.no/api/v1/deploylog",
consoleLogResponseBody: true,
contentType : "APPLICATION_JSON",
httpMode : "POST",
requestBody : veraPayload,
ignoreSslErrors : true
])
slackInfo(msgColor, "_Deploy av fpsak-frontend:$version til $til var suksessfult._")
} else {
slackError("Dette gjelder ${artifactId} til: ${til}")
throw error
}
addBadge icon: '', id: '', link: '', text: "${til}-${version}"
}
}
}
}
}
}
def slackError(String tilleggsinfo) {
slackSend color: "danger", message: "${env.JOB_NAME} [${env.BUILD_NUMBER}] feilet: ${env.BUILD_URL} ${tilleggsinfo}"
}
def slackInfo(String msg) {
slackInfo("#595959", msg)
}
def slackInfo(String color, String msg) {
slackSend color: color, message: msg
}