-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPipeline.jenkinsfile
103 lines (81 loc) · 3.66 KB
/
Pipeline.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
node {
def tag_latest = false
if (env.TAG_LATEST != null) {
tag_latest = Boolean.parseBoolean(TAG_LATEST)
}
if (tag_latest) {
echo "Tagging as latest also"
}
else {
echo "Do not tag as latest"
}
echo "TAG_LATEST=${tag_latest}"
stage('checkout') {
git branch: '${BRANCH}', url: 'https://github.com/hzi-braunschweig/SORMAS-Stats-next-gen.git'
}
stage('Build base image') {
if (params.BUILD_BASE != null && params.BUILD_BASE) {
echo 'Build base image....'
build job: 'Build_SORMAS_Stats_Base', parameters: [string(name: "BRANCH", value: env.BRANCH), string(name: "TAG", value: env.TAG), booleanParam(name: "TAG_LATEST", value: tag_latest) ]
}
else {
echo 'Skipping base image....'
}
}
stage('Build stats image') {
if (params.BUILD_SINGLE != null && params.BUILD_SINGLE) {
withCredentials([ usernamePassword(credentialsId: 'dockerhub', usernameVariable: 'DOCKERUSER', passwordVariable: 'DOCKERPASS' )]) {
dir('sormas-stats-shinyapp') {
echo 'Build stats single image....'
sh """
sudo docker build -f stats.Dockerfile --pull --no-cache --build-arg BRANCH=${BRANCH} -t sormas-stats:${BRANCH} .
sudo docker login -u '${DOCKERUSER}' -p '${DOCKERPASS}' docker.io
sudo docker tag sormas-stats:${BRANCH} docker.io/hzibraunschweig/sormas-stats:${TAG}
sudo docker push docker.io/hzibraunschweig/sormas-stats:${TAG}
sudo docker logout docker.io
echo 'Finished'
"""
}
}
}
else {
echo 'Build stats image....'
build job: 'Build_SORMAS_Stats', parameters: [string(name: "BRANCH", value: env.BRANCH), string(name: "TAG", value: env.TAG), booleanParam(name: "TAG_LATEST", value: tag_latest) ]
}
}
def credentials_id = params.CREDENTIALS_ID
stage('Deploy to server') {
if (env.SERVER_LIMIT != null && env.SERVER_LIMIT.trim() != '') {
withCredentials([ usernamePassword(credentialsId: credentials_id, usernameVariable: 'ANSIBLE_USER', passwordVariable: 'ANSIBLE_PASS' )]) {
sh """
job_result=\$(awx --conf.host 'https://${ANSIBLE_TOWER}' --conf.username ${ANSIBLE_USER} --conf.password ${ANSIBLE_PASS} \
job_templates launch --monitor --wait --inventory ${ANSIBLE_INVENTORY} --extra_vars "stats_image: docker.io/hzibraunschweig/sormas-stats:${TAG}" --limit '${SERVER_LIMIT}' 316)
echo \$job_result
"""
}
}
else {
echo "Skipping deploy to server"
}
}
stage('Create release') {
if (env.GITHUB_CREDENTIALS != null && env.GITHUB_CREDENTIALS.trim() != '' ) {
withCredentials([ usernamePassword(credentialsId: env.GITHUB_CREDENTIALS, usernameVariable: 'GITHUB_USER', passwordVariable: 'GITHUB_PASS' )]) {
sh """
git config --local credential.username ${GITHUB_USER}
git config --local credential.helper '!f() { echo password=${GITHUB_PASS}; }; f'
git tag -a -f v${TAG} -m "Build ${currentBuild.number}"
git push https://github.com/hzi-braunschweig/SORMAS-Stats-next-gen.git -f --tags
"""
}
}
else {
echo "No GITHUB_CREDENTIALS specified - skipping release"
}
def displayName = "${TAG}"
if (tag_latest) {
displayName = displayName + ' - latest'
}
currentBuild.displayName = displayName
}
}