forked from cloudbees/devoptics-quickstart-app
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
88 lines (83 loc) · 2.48 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
79
80
81
82
83
84
85
86
87
88
def label = UUID.randomUUID().toString()
timestamps {
podTemplate(label: label, yaml: """
apiVersion: v1
kind: Pod
spec:
serviceAccountName: jenkins
containers:
- name: maven
command:
- cat
tty: true
env:
- name: MAVEN_OPTS
value: -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
- name: BUILD_NUMBER
value: ${env.BUILD_NUMBER}
- name: BRANCH_NAME
value: ${env.BRANCH_NAME}
- name: _JAVA_OPTIONS
value: -Xmx300M
image: maven:3.5.4-jdk-8
resources:
limits:
memory: 1500Mi
requests:
cpu: 100m
memory: 1500Mi
- name: docker
command:
- cat
tty: true
image: docker:18.09
env:
- name: BUILD_NUMBER
value: ${env.BUILD_NUMBER}
- name: BRANCH_NAME
value: ${env.BRANCH_NAME}
volumeMounts:
- name: 'docker-socket'
mountPath: /var/run/docker.sock
- name: kubectl
image: gcr.io/cloud-builders/kubectl
command:
- cat
tty: true
volumes:
- name: 'docker-socket'
hostPath:
path: /var/run/docker.sock
type: File
""") {
node(label) {
stage('Checkout') {
checkout scm
}
stage('Package') {
try {
container('maven') {
sh 'mvn -B clean install -Dmaven.test.skip=true'
}
container('docker'){
withCredentials([usernamePassword( credentialsId: 'fb615dd7-9a9c-416c-b747-8a55b473bc41', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
docker.withRegistry('', 'fb615dd7-9a9c-416c-b747-8a55b473bc41') {
sh "docker login -u ${USERNAME} -p ${PASSWORD}"
def dockerImage = docker.build("ottovsky/devoptics-quickstart-app:${env.BUILD_ID}")
dockerImage.push()
}
}
}
} finally {
archiveArtifacts allowEmptyArchive: true, artifacts: '**/target/*.jar'
}
}
stage('Deploy to k8s') {
container('kubectl'){
sh "kubectl get deployment devoptics-staging && kubectl set image deployment/devoptics-staging devoptics-staging=ottovsky/devoptics-quickstart-app:${env.BUILD_ID} || echo"
sh "kubectl get deployment devoptics-staging || kubectl run --image ottovsky/devoptics-quickstart-app:${env.BUILD_ID} devoptics-staging -- /bin/sh -c 'while true; do java -cp /devoptics-quickstart-1.0-SNAPSHOT.jar devoptics.App; sleep 5; done'"
}
}
}
}
}