-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
78 lines (73 loc) · 2.08 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
pipeline {
agent any
environment {
BRANCH = 'master'
HELM_STATE_GIT_REPO = 'github.com/infracloudio/app-mono-helmstate.git'
HELM_STATE_REPO = 'app-mono-helmstate'
DOCKERHUB_HOOK_SECRET = "dockerhub-webhook-secret"
//GIT = credentials('github-credentials')
GIT_USR = ""
GIT_PSW = ""
}
stages {
stage('configure webook') {
steps {
script {
setupWebhook()
}
}
}
stage('Update values.yaml in app-mono-helmstate') {
steps {
updateValuesfile()
}
}
}
post {
cleanup {
deleteDir()
}
}
}
def setupWebhook() {
properties([
pipelineTriggers([
[$class: 'GenericTrigger',
genericVariables: [
[key: 'TAG', value: '$.push_data.tag'],
[key: 'IMAGE', value: '$.repository.name'],
[key: 'REPONAME', value: '$.repository.repo_name'],
],
causeString: 'Triggered on docker push',
token: env.DOCKERHUB_HOOK_SECRET,
printContributedVariables: true,
printPostContent: true,
]
])
])
}
def updateValuesfile() {
if (IMAGE != "") {
env.IMAGE = IMAGE
env.TAG = TAG
sh '''
git clone https://${GIT_USR}:${GIT_PSW}@${HELM_STATE_GIT_REPO}
cd ${HELM_STATE_REPO}
git checkout ${BRANCH}
git reset --hard origin/${BRANCH}
ls -l
'''
sh "sed -i 's/\\btag.*\\b/tag: $TAG/g' ${HELM_STATE_REPO}/$IMAGE/values.yaml"
sh '''
cd ${HELM_STATE_REPO}
git branch
git diff
git status
git config user.name ${GIT_USR}
git config user.email ${GIT_USR}@users.noreply.github.com
git add $IMAGE/values.yaml
git commit -m \"Jenkins: Update image tag in $IMAGE/values.yaml to $TAG\"
git push https://${GIT_USR}:${GIT_PSW}@${HELM_STATE_GIT_REPO}
'''
}
}