generated from ytgov/vue-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Jenkinsfile
69 lines (58 loc) · 2.64 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
pipeline {
agent any
environment {
USER_CREDENTIALS = credentials('srv-jenkins')
NAME = "sfa"
VERSION = "${env.BUILD_ID}-${env.GIT_COMMIT}"
IMAGE = "${NAME}:${VERSION}"
HARBOR_URL = "10.230.7.2"
HARBOR_PROJECT = "eserv-tst-ns"
}
triggers {
githubPush()
}
stages {
stage('Build and Push') {
steps {
script {
def app = docker.build("${HARBOR_URL}/${HARBOR_PROJECT}/${NAME}:${VERSION}")
docker.withRegistry("https://${HARBOR_URL}", "srv-jenkins-domain") {
app.push()
app.push("latest")
}
}
}
}
stage('Remove local image') {
steps {
sh "docker rmi ${HARBOR_URL}/${HARBOR_PROJECT}/${NAME}:${VERSION}"
}
}
stage('Deploy') {
steps {
sh 'tkc=$(curl -XPOST -u [email protected]:$USER_CREDENTIALS_PSW https://10.230.7.1/wcp/login -k -d \'{"guest_cluster_name":"eserv-tst-cluster"}\' -H "Content-Type: application/json"); tkc_server=$(echo $tkc | jq -r .guest_cluster_server); tkc_session=$(echo $tkc | jq -r .session_id); kubectl config set-cluster $tkc_server --server=https://$tkc_server:6443 --insecure-skip-tls-verify=true; kubectl config set-context tkc-context-prod --cluster=$tkc_server; kubectl --context tkc-context-prod apply -f yaml/ -n sfa --token=$tkc_session'
}
}
stage('Refresh deployments') {
steps {
sh 'tkc=$(curl -XPOST -u [email protected]:$USER_CREDENTIALS_PSW https://10.230.7.1/wcp/login -k -d \'{"guest_cluster_name":"eserv-tst-cluster"}\' -H "Content-Type: application/json"); tkc_server=$(echo $tkc | jq -r .guest_cluster_server); tkc_session=$(echo $tkc | jq -r .session_id); kubectl config set-cluster $tkc_server --server=https://$tkc_server:6443 --insecure-skip-tls-verify=true; kubectl config set-context tkc-context-prod --cluster=$tkc_server; kubectl --context tkc-context-prod -n sfa rollout restart deployment sfa-deployment --token=$tkc_session'
}
}
}
post {
always {
emailext (
to: '[email protected]',
subject: '$DEFAULT_SUBJECT',
body: '$DEFAULT_CONTENT , ${GIT_REVISION} is the git commit ID, build number ${BUILD_NUMBER} ',
mimeType: 'text/html'
);
}
success {
echo 'Build complete'
}
failure {
echo 'Build failed'
}
}
}