-
Notifications
You must be signed in to change notification settings - Fork 8
/
Jenkinsfile
73 lines (70 loc) · 1.74 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
podTemplate(yaml: """
apiVersion: v1
kind: Pod
metadata:
labels:
jenkins/kube-default: true
app: jenkins
component: agent
spec:
containers:
- name: jnlp
image: jenkinsci/jnlp-slave:latest
resources:
limits:
cpu: 1
memory: 2Gi
requests:
cpu: 1
memory: 2Gi
imagePullPolicy: Always
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: DOCKER_HOST
value: tcp://localhost:2375
- name: docker
image: docker:latest
command:
- cat
tty: true
volumeMounts:
- mountPath: /var/run/docker.sock
name: docker-sock
- name: maven
image: maven:3.6.3-jdk-8
tty: true
command:
- cat
volumes:
- name: docker-sock
hostPath:
path: /var/run/docker.sock
"""
){
node(POD_LABEL) {
def serverVersion=''
stage('Checkout'){
checkout scm
}
container('maven'){
stage('Get Versions'){
serverVersion = sh(returnStdout: true, script: 'cd backend && mvn help:evaluate -Dexpression=project.version -q -DforceStdout').trim()
}
}
container('docker'){
stage('Build Docker Image') {
sh "cd backend && docker build --tag tommyelroy/coronatracker-server:$serverVersion --build-arg VERSION=$serverVersion ."
}
if(env.BRANCH_NAME=='master'){
stage('Push Docker Image'){
withCredentials([string(credentialsId: 'dockerhub-tommyelroy-passwort', variable: 'password')]) {
sh "docker login --username='tommyelroy' --password='$password' && docker push tommyelroy/coronatracker-server:$serverVersion"
}
}
}
}
}
}