-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathJenkinsfile
105 lines (99 loc) · 3.67 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
// The folderName is used below when giving name to all the jobs. This to ensure that they end up in the correct folder.
def folderName = 'conan'
// Name/label of the worker that should be used, this name is also set in the individual build jobs Jenkinsfile
def worker_node = 'buildpkg-ubuntu1804'
// Settings for conan
def conan_user = 'includeos'
def conan_channel = 'test'
def conan_home = '/home/ubuntu'
def conan_remote = 'includeos'
// Create a folder to keep all the jobs that are created in. Also create views based on what type of build job it is.
stage('Create folders') {
node() {
jobDsl scriptText: """
folder("${folderName}") {
displayName('Conan')
description('Build jobs for all IncludOS dependencies built with Conan')
views {
listView('dependencies') {
jobs {
regex('dependencies-.+')
}
columns {
status()
weather()
name()
lastSuccess()
lastFailure()
lastDuration()
buildButton()
}
}
}
}
"""
}
}
stage('Create jobs') {
node("${worker_node}") {
// Checkout the repo to get all the Jenkinsfiles and create build jobs
checkout scm
// Find the url of the repo, and use this when generating the pipelinejobs
def git_url = sh(returnStdout: true, script: 'git config remote.origin.url').trim()
// Find all Jenkinsfiles in the whole catalog
def jenkinsfiles = findFiles(glob: '**/Jenkinsfile')
// Regex used to remove the fileName and only have the paths
def regexSuffix = ~/\/Jenkinsfile$/
// All job creation will be run in parallel
def jobs = [:]
for (def file: jenkinsfiles) {
if ("${file.path}" == "Jenkinsfile") {
echo "Skipping root Jenkinsfile"
continue
}
// Remove file name, modify path and append folder name
// final name should be of the format: <folderName>/<path>-<name>
String name = "${file.path}" - regexSuffix
name = name.replace("/", "-")
name = "${folderName}/${name}"
def path = "${file.path}" // trick to avoid overwriting when using parallel
// Add the jobDsl script to the jobs list
jobs["${name}"] = {
jobDsl scriptText: """
pipelineJob("${name}") {
description("Pipeline for ${name}")
environmentVariables {
env('SCRIPT_PATH', "${path}")
env('CONAN_USER', "${conan_user}")
env('CONAN_CHANNEL', "${conan_channel}")
env('CONAN_USER_HOME', "${conan_home}")
env('CONAN_REMOTE', "${conan_remote}")
}
definition {
cpsScm {
lightweight(true)
scm {
git {
remote {
url("${git_url}")
credentials('jenkins-includeos-user-pass')
}
branch('master')
scriptPath("${path}")
extensions {
cleanBeforeCheckout()
}
}
}
}
}
}
"""
// Call build to initiate the job properly, this causes the pipeline to run once. This makes sure that the parameters are available when the job is to be run for real. It is called with default parameters, and when version='' the build job is not actually run.
build "${name}"
}
}
// Run all the loaded jobs in parallel. At this point they will have to be manually approved in the "In-process Script approval" console in Jenkins.
parallel jobs
}
}