-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgimpBuildPipeline.groovy
213 lines (206 loc) · 8 KB
/
gimpBuildPipeline.groovy
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
/*
* This build pipeline is designed to automatically run builds for the following projects:
*
* - BABL
* - GEGL
* - libmypaint
* - mypaint-brushes
* - GIMP
*
* The pipeline will select appropriate build scripts depending on the project calling it.
*/
import jenkins.model.Jenkins
/**
Does nothing except return a static Map.
*/
@NonCPS
Map projectEnvMap() {
[
gimp: [
master: [
GEGL_BRANCH: 'master'
],
'gimp-2-10': [
GEGL_BRANCH: 'master'
],
'gimp-2-8': [
GEGL_BRANCH: 'gegl-0-2'
]
]
]
}
/**
List of projects and branches in which to copy dependencies from.
*/
@NonCPS
List<String> projectDependencies(String project, String branch) {
[
gegl: [
master: [
'babl/master'
],
'gegl-0-2': [
'babl/master'
]
],
libmypaint: [
'v1.3.0': [
'babl/master',
'gegl/master'
]
],
'mypaint-brushes': [
'v1.3.x': [
'babl/master',
'gegl/master',
'libmypaint/v1.3.0'
]
],
gimp: [
'master': [
'babl/master',
'gegl/master',
'libmypaint/v1.3.0',
'mypaint-brushes/v1.3.x'
],
'gimp-2-10': [
'babl/master',
'gegl/master',
'libmypaint/v1.3.0',
'mypaint-brushes/v1.3.x'
],
'gimp-2-8': [
'babl/master',
'gegl/gegl-0-2',
'libmypaint/v1.3.0',
'mypaint-brushes/v1.3.x'
]
]
].get(project)?.get(branch) ?: []
}
@NonCPS
String getFriendlyName(String name) {
[
'babl': 'BABL',
'gegl': 'GEGL',
'gimp': 'GIMP'
].get(name) ?: name
}
/**
References the project environment map and converts variables into Docker
arguments for environment variables.
*/
@NonCPS
String getDockerEnv(String project, branch) {
projectEnvMap().get(project)?.get(branch)?.collect { k, v ->
"-e ${k}=${v}"
}?.join(' ') ?: ''
}
/**
Check to see if a dependency is ready. Only used during first time build on
a new Jenkins instance.
*/
@NonCPS
Boolean isDependentBuildReady(String dependency) {
Jenkins.instance.getItemByFullName(dependency)?.lastSuccessfulBuild ? true : false
}
/**
This is the main execution.
*/
def call() {
//e.g. project = gimp
String project = env.JOB_NAME.tokenize('/')[0]
//e.g. -e GIMP_BRANCH=master -e GEGL_BRANCH=master
String myEnv = "-e ${project.toUpperCase()}_BRANCH=${env.BRANCH_NAME} " + getDockerEnv(project, env.BRANCH_NAME)
String reference_repo = "${Jenkins.instance.root}/export/${project}.git"
if(Integer.parseInt(env.BUILD_NUMBER) == 1) {
//wait for dependent builds to finish when Jenkins is bootstrapped for the first time
while(false in projectDependencies(project, env.BRANCH_NAME).collect { isDependentBuildReady(it) }) {
echo "Waiting on first build of ${projectDependencies(project, env.BRANCH_NAME).find { !isDependentBuildReady(it) }}."
sleep 60
}
}
node('master') {
stage("Environment") {
docker.image('gimp/gimp:latest').inside("${myEnv}") {
sh '''
|head -n1 /etc/issue
|id
|uname -rms
|bash --version | head -n1
'''.stripMargin().trim()
//environment_string = sh(script: 'env | LC_ALL=C sort', returnStdout: true).split('\n').join('\n ')
grep_expr = 'BRANCH|^BUILD_|^JOB_|PATH|^DEBIAN_FRONTEND|^PREFIX|ACLOCAL_FLAGS|^PWD'
environment_string = sh(script: "env | LC_ALL=C sort | grep -E \'${grep_expr}\'", returnStdout: true).split('\n').join('\n ')
echo "DOCKER ENVIRONMENT:\n ${environment_string}"
}
}
stage("Update git cache") {
lock('update-git-cache') {
sh """
|#!/bin/bash
|echo 'Updating local git cache for faster checkouts'
|function update_cached_scm {
| name="\$1"
| repoUrl="\$2"
| localRepo="${Jenkins.instance.root}/export/\${name}.git"
| if [ ! -d "\${localRepo}" ]; then
| git clone --mirror "\${repoUrl}" "\${localRepo}"
| fi
| cd "\${localRepo}"
| git remote update --prune
|}
|set -exo pipefail
|update_cached_scm "docker-jenkins-gimp" "https://github.com/gimp-ci/docker-jenkins-gimp"
|update_cached_scm "${project}" "${scm.userRemoteConfigs[0].url}"
""".stripMargin().trim()
}
//check out project to subdirectory for build
dir(project) {
checkout scm
}
}
docker.image('gimp/gimp:latest').inside("${myEnv} -v ${reference_repo}:${reference_repo}:ro") {
if(projectDependencies(project, env.BRANCH_NAME)) {
stage('Copy Dependencies') {
for(String dependency : projectDependencies(project, env.BRANCH_NAME)) {
copyArtifacts filter: '**/*-internal.tar.gz', fingerprintArtifacts: true, flatten: true, projectName: dependency, selector: lastSuccessful()
sh 'mv *-internal.tar.gz /data/'
}
}
}
catchError {
stage("Build ${getFriendlyName(project)}") {
//automatically generated checkout command from pipeline syntax generator
checkout poll: false, scm: [$class: 'GitSCM', branches: [[name: 'refs/heads/master']], browser: [$class: 'GithubWeb', repoUrl: 'https://github.com/gimp-ci/docker-jenkins-gimp'], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'ChangelogToBranch', options: [compareRemote: 'origin', compareTarget: 'master']], [$class: 'RelativeTargetDirectory', relativeTargetDir: 'docker-jenkins-gimp'], [$class: 'CloneOption', depth: 0, noTags: true, reference: "${Jenkins.instance.root}/export/docker-jenkins-gimp.git", shallow: false]], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/gimp-ci/docker-jenkins-gimp']]]
//end automatically generated checkout
sh "SKIP_MAKE_CHECK=1 bash ./docker-jenkins-gimp/debian-testing/${project}.sh"
}
}
if((project in ['babl', 'gegl', 'gimp']) && Integer.parseInt(env.BUILD_NUMBER) > 1) {
catchError {
stage("Test ${getFriendlyName(project)}") {
sh "SKIP_MAKE_BUILD=1 bash ./docker-jenkins-gimp/debian-testing/${project}.sh"
}
}
catchError {
stage("${getFriendlyName(project)} distcheck") {
sh "SKIP_MAKE_BUILD=1 SKIP_MAKE_CHECK=1 INCLUDE_DISTCHECK=1 bash ./docker-jenkins-gimp/debian-testing/${project}.sh"
}
}
}
stage("Publish artifacts") {
//archive artifacts relative to project directory
dir(project) {
if(project == 'gegl') {
archiveArtifacts artifacts: "${project}-internal.tar.gz,*.tar.bz2,**/test-suite.log,tests/mipmap/*.png", fingerprint: true, onlyIfSuccessful: false
}
else {
archiveArtifacts artifacts: "${project}-internal.tar.gz,*.tar.bz2,**/test-suite.log", fingerprint: true, onlyIfSuccessful: false
}
}
}
}
deleteDir()
}
}