-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
137 lines (136 loc) · 3.9 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
def label = "buildpod.${env.JOB_NAME}".replaceAll(/[^A-Za-z-]+/, '-').take(62) + "p"
podTemplate(
name: label,
label: label,
containers: [
containerTemplate(
name: 'build-golang',
image: 'docker.io/bborbe/build-golang:1.0.0',
ttyEnabled: true,
command: 'cat',
resourceRequestCpu: '500m',
resourceRequestMemory: '500Mi',
resourceLimitCpu: '2000m',
resourceLimitMemory: '1000Mi',
),
containerTemplate(
name: 'build-docker',
image: 'docker.io/bborbe/build-docker:1.0.0',
ttyEnabled: true,
command: 'cat',
privileged: true,
resourceRequestCpu: '500m',
resourceRequestMemory: '500Mi',
resourceLimitCpu: '2000m',
resourceLimitMemory: '500Mi',
),
],
volumes: [
secretVolume(mountPath: '/home/jenkins/.docker', secretName: 'docker'),
hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock'),
],
inheritFrom: '',
namespace: 'jenkins',
serviceAccount: '',
workspaceVolume: emptyDirWorkspaceVolume(false),
) {
node(label) {
properties([
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '3', numToKeepStr: '5')),
pipelineTriggers([
cron('H 2 * * *'),
pollSCM('H/5 * * * *'),
]),
parameters([
string(name: 'Version', defaultValue: '', description: 'Version to build'),
]),
])
try {
container('build-golang') {
stage('Golang Checkout') {
timeout(time: 5, unit: 'MINUTES') {
checkout([
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions: scm.extensions + [[$class: 'CloneOption', noTags: false, reference: '', shallow: true]],
submoduleCfg: [],
userRemoteConfigs: scm.userRemoteConfigs
])
}
}
stage('Golang Link') {
timeout(time: 5, unit: 'MINUTES') {
sh """
mkdir -p /go/src/github.com/bborbe
ln -s `pwd` /go/src/github.com/seibert-media/dimios
"""
}
}
stage('Golang Test') {
timeout(time: 15, unit: 'MINUTES') {
sh "cd /go/src/github.com/seibert-media/dimios && make test"
}
}
}
container('build-docker') {
stage('Docker Checkout') {
timeout(time: 5, unit: 'MINUTES') {
checkout([
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions: scm.extensions + [[$class: 'CloneOption', noTags: false, reference: '', shallow: true]],
submoduleCfg: [],
userRemoteConfigs: scm.userRemoteConfigs
])
}
}
stage('Docker Trigger') {
timeout(time: 5, unit: 'MINUTES') {
env.TRIGGER = sh (script: "VERSION=${params.Version} make trigger", returnStdout: true).trim()
echo "trigger = ${env.TRIGGER}"
}
}
stage('Docker Build') {
if (env.TRIGGER == 'build' || env.BRANCH_NAME != 'master') {
timeout(time: 15, unit: 'MINUTES') {
sh "VERSION=${params.Version} make build"
}
}
}
stage('Docker Upload') {
if (env.TRIGGER == 'build' && env.BRANCH_NAME == 'master') {
timeout(time: 15, unit: 'MINUTES') {
sh "VERSION=${params.Version} make upload"
}
}
}
stage('Docker Clean') {
if (env.TRIGGER == 'build' || env.BRANCH_NAME != 'master') {
timeout(time: 5, unit: 'MINUTES') {
sh "VERSION=${params.Version} make clean"
}
}
}
}
currentBuild.result = 'SUCCESS'
} catch (any) {
currentBuild.result = 'FAILURE'
throw any //rethrow exception to prevent the build from proceeding
} finally {
if ('FAILURE'.equals(currentBuild.result)) {
emailext(
body: '${DEFAULT_CONTENT}',
mimeType: 'text/html',
replyTo: '$DEFAULT_REPLYTO',
subject: '${DEFAULT_SUBJECT}',
to: emailextrecipients([
[$class: 'CulpritsRecipientProvider'],
[$class: 'RequesterRecipientProvider']
])
)
}
}
}
}