forked from katson95/pet-clinic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
61 lines (53 loc) · 2.32 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
def label = "mypod-${UUID.randomUUID().toString()}"
podTemplate(label: label,
containers: [
containerTemplate(name: 'i360-agent', image: 'katson95/i360-agent:2.0',ttyEnabled: true, command: 'cat'),
containerTemplate(name: 'maven', image: 'maven:3.3.9-jdk-8-alpine', ttyEnabled: true, command: 'cat'),
containerTemplate(name: 'a-360', image: 'katson95/a-360:latest', ttyEnabled: true, command: 'cat'),
],
volumes: [
persistentVolumeClaim(mountPath: '/root/.m2/repository', claimName: 'jenkins', readOnly: false),
hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock')
]) {
node(label) {
checkout scm
dir('pet-clinic-k8') {
git url: 'https://github.com/katson95/pet-clinic-k8.git'
}
def IMAGE_NAME = 'katson95/pet-clinic'
def IMAGE_VERSION = 'latest'
stage('Get a Maven project') {
container('maven') {
stage('Build a Maven project') {
sh 'mvn -B clean install'
}
}
}
stage('Build and Test Image') {
container('a-360') {
stage('Package into Docker Image') {
sh 'docker build -t pet-clinic:latest .'
sh 'docker tag pet-clinic:latest docker.ops.dev.invent-360.com/katson95/pet-clinic:latest'
}
}
}
stage('Publish Image') {
container('a-360'){
stage('Publish Image to Docker Registry') {
withCredentials([usernamePassword(credentialsId: 'i360-nexus-id', passwordVariable: 'dockerPassword', usernameVariable: 'dockerUsername')]) {
sh "docker login -u ${env.dockerUsername} -p ${env.dockerPassword} docker.ops.dev.invent-360.com"
sh "docker push docker.ops.dev.invent-360.com/${IMAGE_NAME}:${IMAGE_VERSION}"
}
}
}
}
stage('Deploy To UAT') {
container('i360-agent'){
stage('Deploy To uat') {
sh 'kubectl get ns uat || kubectl create ns uat'
sh 'kubectl create -f ./pet-clinic-k8/ --namespace=uat'
}
}
}
}
}