This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
158 lines (126 loc) · 3.24 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env groovy
def job_desc = """
Jenkins multibranch job for kind-minefiled
<br/>
<a href='https://github.com/nvtkaszpir/kind-minefield'>github</a>
"""
pipeline {
agent { label 'k8s' }
options {
timeout(time: 1, unit: 'HOURS')
disableConcurrentBuilds()
ansiColor('xterm')
timestamps() // breaks ansiColor plugin
lock resource: 'kind-cluster'
}
// notice that parameters are dynamically updated in first stage
// parameters {
// }
stages {
stage('Reconfig job'){
steps {
script{
def job = Jenkins.instance.getItemByFullName(job_name)
// change description
def pr_desc = ""
if ( env.CHANGE_ID != null) {
pr_desc += "<br/>"
pr_desc += "<br/>"
pr_desc += "<br/>"
pr_desc += "<h2>Change URL: <a href='${env.CHANGE_URL}'>${env.CHANGE_TITLE}</a></h2><br/>"
}
job.setDescription(job_desc + pr_desc)
job.save()
}
}
}
stage('review') {
when {
// run review step if this is PR and the PR is not from repo owner
expression { (env.CHANGE_ID != null) && (env.CHANGE_AUTHOR != 'nvtkaszpir') }
}
steps {
script {
approve = input(message: "Continue with build?", submitter: 'kaszpir', parameters: [
choice(
name: 'result',
choices: ["No", "Yes"].join("\n"),
description: "Please review the code and continue build if it looks good."
)
])
if (approve == "Yes") {
println "Review stage approved."
}
else
{
currentBuild.result = 'ABORTED'
error("Review stage not approved.")
}
}
}
}
stage('KinD up'){
steps {
sh '''
kind version
kind delete cluster || true
kind create cluster --config kind-config.yaml --image "kindest/node:v1.13.10" --wait 5m
'''
// export KUBECONFIG env var used later by kind and kubectl
script {
env.KUBECONFIG = sh(
returnStdout: true,
script: 'kind get kubeconfig-path --name="kind"'
).trim()
}
}
}
stage('KinD info'){
steps {
sh '''
export | sort
kubectl cluster-info
kubectl get nodes
kubectl get pods -A
'''
}
}
stage('k8s'){
steps {
sh '''
kubectl apply -f provision/kubectl/
'''
}
}
stage('helm'){
agent {
docker {
label 'k8s'
image 'alpine/helm:2.13.1'
args '--network=host -v ${HOME}/.kube:/tmp/.kube:ro --entrypoint="" '
}
}
environment {
KUBECONFIG='/tmp/.kube/kind-config-kind'
HELM_HOME='/tmp/.helm'
}
steps {
sh '''
env
export
helm init --service-account tiller --wait
helm version
'''
}
}
}
post {
always {
sh '''
kind delete cluster || true
'''
archiveArtifacts allowEmptyArchive: true, artifacts: '**/reports/*', excludes: '**/*.gitkeep', fingerprint: true
deleteDir()
}
}
}