-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
91 lines (89 loc) · 2.54 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
89
90
91
/*6
This pipeline is used to sync git state to deployed state.
Any app.version file update will trigger this pipeline to sync state.
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CALCULATED VARIABLES
LABEL_NAME = 'agent-' + new Date().getTime()
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
pipeline {
agent {
kubernetes {
label "$LABEL_NAME"
yaml '''
apiVersion: v1
kind: Pod
spec:
serviceAccountName: jenknis-jenkins
containers:
- name: app-builder
image: docker:latest
command: ['cat']
tty: true
volumeMounts:
- name: dockersock
mountPath: /var/run/docker.sock
volumes:
- name: dockersock
hostPath:
path: /var/run/docker.sock
'''
}
}
environment {
GIT_SSH_COMMAND = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
TAG = "${env.BUILD_NUMBER}"
registryCredential = 'Docker'
}
stages {
// stage('GitClone') {
// steps {
// container('app-builder') {
// script {
// git url: 'https://github.com/adavarski/k3d-jenkins-playground.git'
// }
// }
// }
// }
stage('Prepared') {
steps {
container('app-builder') {
sh '''
apk update
apk add curl
apk add git
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
mv kubectl /usr/local/bin
chmod +x /usr/local/bin/kubectl
git clone https://github.com/adavarski/k3d-cicd-playground
'''
}
}
}
stage('Build') {
steps {
container('app-builder') {
script {
docker.withRegistry( 'https://index.docker.io/v1/', registryCredential ) {
sh '''
cd k3d-cicd-playground/sample-service
docker build -t davarski/sample-app:1.0 .
docker push davarski/sample-app:1.0
'''
}
}
}
}
}
stage('Deploy') {
steps {
container('app-builder') {
sh '''
/usr/local/bin/kubectl apply -f k3d-cicd-playground/sample-service/k8s-manifest/Deployment.yaml
/usr/local/bin/kubectl rollout restart deployment app-server --namespace=default
'''
}
}
}
}
}