-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathJenkinsfile
230 lines (228 loc) · 6.08 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/usr/bin/env groovy
pipeline {
agent {
kubernetes {
inheritFrom "default"
// by default workspaceVolume is emptyDir
// https://www.jenkins.io/doc/pipeline/steps/kubernetes/#podtemplate-define-a-podtemplate-to-use-in-the-kubernetes-plugin
// ReadWriteOnce and default storageClass is enough for build even with parallel stages as all agent containers are part of the same pod
workspaceVolume dynamicPVC(requestsSize: "20Gi", accessModes: "ReadWriteOnce")
label validLabel("learning-${env.BRANCH_NAME}") // subsequent builds from the same branch will reuse pods
idleMinutes 60 // pod will be available to reuse for 1 h
//Ensures all containers use the same user id as jnlp container to mitigate issue
//https://github.com/jenkinsci/kubernetes-plugin#pipeline-sh-step-hangs-when-multiple-containers-are-used
yaml """
apiVersion: v1
kind: Pod
metadata:
labels:
purpose: ci
spec:
securityContext:
runAsUser: 1000
fsGroup: 1000
containers:
- name: maven-jdk21
image: maven:3-eclipse-temurin-21
command:
- sleep
args:
- infinity
volumeMounts:
- mountPath: /home/jenkins/agent
name: workspace-volume
- name: golang
image: golang:1.23
command:
- sleep
args:
- infinity
volumeMounts:
- mountPath: /home/jenkins/agent
name: workspace-volume
- name: python
image: quay.io/matihost/ansible:latest
command:
- cat
tty: true
volumeMounts:
- mountPath: /home/jenkins/agent
name: workspace-volume
- name: rust
image: rust
command:
- cat
tty: true
volumeMounts:
- mountPath: /home/jenkins/agent
name: workspace-volume
- name: ansible
image: quay.io/matihost/ansible:latest
command:
- sleep
args:
- infinity
volumeMounts:
- mountPath: /home/jenkins/agent
name: workspace-volume
- name: kubectl
image: bitnami/kubectl:latest
command:
- sleep
args:
- infinity
volumeMounts:
- mountPath: /home/jenkins/agent
name: workspace-volume
"""
}
}
options{
buildDiscarder(logRotator(numToKeepStr: '10'))
timeout(time: 1, unit: 'HOURS')
skipDefaultCheckout() // to avoid auto checkout sources matching Jenkinsfile, if skipped pipeline needs to call: checkout scm
skipStagesAfterUnstable()
parallelsAlwaysFailFast()
timestamps()
}
triggers {
pollSCM('H/10 * * * 1-5')
}
stages {
stage('Checkout sources') {
steps {
// when no tags info is required
// checkout scm
// checkout with tags info so that git describe is able to work
checkout([
$class : 'GitSCM',
branches : scm.branches,
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions : scm.extensions + [[$class: 'CloneOption', noTags: false]],
userRemoteConfigs : scm.userRemoteConfigs,
])
}
}
stage('Build') {
parallel {
stage('Build :: Java') {
steps {
container("maven-jdk21"){
dir("java"){
echo "Building ${pwd()}..."
sh """
mvn -s .mvn/settings.xml clean install
"""
}
}
}
post{
always {
dir("java"){
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
junit '**/target/surefire-reports/*.xml'
}
}
}
}
stage('Build :: Project Euler') {
steps {
container("maven-jdk21"){
dir("algorithms/project-euler"){
echo "Building ${pwd()}..."
sh """
mvn -s .mvn/settings.xml clean install
"""
}
}
}
post{
always {
dir("algorithms/project-euler"){
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
}
}
}
}
stage('Build :: Golang') {
steps {
container("golang"){
dir("go/learning"){
echo "Building ${pwd()}..."
sh """
export GOCACHE=/home/jenkins/agent/workspace/.gocache
make build
"""
}
}
}
post{
always {
dir("go"){
archiveArtifacts artifacts: '**/language', fingerprint: true
}
}
}
}
stage('Build :: Rust') {
steps {
container("rust"){
dir("rust/guessing_game"){
echo "Building ${pwd()}..."
sh """
make build
"""
}
}
}
}
stage('Build :: Python') {
steps {
container("python"){
dir("python/apps/exchange-rate"){
echo "Building ${pwd()}..."
sh """
make build
make install
exchange-rate
"""
}
}
}
}
stage('Build :: Ansible') {
steps {
container("ansible"){
dir("ansible/learning"){
echo "Building ${pwd()}..."
sh """
make dictionaries.yaml
"""
}
}
}
}
stage('Build :: Kubectl') {
steps {
container("kubectl"){
echo "Running kubectl ${pwd()}..."
sh """
kubectl version
"""
}
}
}
}
}
}
}
/**
* Helper method to ensure label given to pod follow K8S naming rules
*/
def validLabel(String str){
str = str.replaceAll('[^A-Za-z0-9]','-')
if (str.length() > 63){
str = str.substring(0, 63)
}
return str
}