-
Notifications
You must be signed in to change notification settings - Fork 14
/
JenkinsfileTrigger
129 lines (116 loc) · 4.43 KB
/
JenkinsfileTrigger
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
// Name of project in OpenShift
def project = "tensorflow"
// Map of OS targets to test Tensorflow with
// Key: name of os, Value: s2i image registry
def buildTargets = [
"fedora26": "registry.fedoraproject.org/f26/s2i-core",
"fedora27": "registry.fedoraproject.org/f27/s2i-core",
"fedora28": "registry.fedoraproject.org/f28/s2i-core",
"centos7": "openshift/base-centos7"
]
// list of python versions to be used when testing
def pythonVersions = ["2.7", "3.5", "3.6"]
// List of templates needed for the build process
def templates = ["tensorflow-build-image.json", "tensorflow-build-job.json"]
node {
try {
withCredentials([string(credentialsId: 'tensorflowWebhookToken', variable: 'tensorflowWebhookToken')]) {
properties([
[$class: 'GithubProjectProperty', displayName: '', projectUrlStr: 'https://github.com/tensorflow/tensorflow/'],
pipelineTriggers([
[$class: 'GenericTrigger',
genericVariables: [
[key: 'release_version', value: '$.release.tag_name'],
],
genericHeaderVariables: [
[key: 'X-GitHub-Event', regexpFilter: '']
],
token: tensorflowWebhookToken,
regexpFilterText: '$x_github_event',
regexpFilterExpression: '^release$'
]
])
])
}
stage("Checkout") {
checkout scm
}
stage("Create Templates") {
openshift.withCluster() {
openshift.withProject(project) {
// Loop through templates and make sure they exist in OpenShift
templates.each { template ->
def templateFileName = template.take(template.lastIndexOf("."))
def templateSelector = openshift.selector("template", templateFileName)
if (!templateSelector.exists()) {
openshift.create(readFile(template))
} else {
openshift.replace(readFile(template))
}
}
}
}
}
stage("Tensorflow-Trigger") {
def builds = [:]
// Loop through all the OS targets we will be building
buildTargets.each { operatingSystem, s2iImage ->
// Loop through the different versions of python we want to test
pythonVersions.each { pythonVersion ->
// Check existance of the jenkins job "tensorflow-${operatingSystem}-${pythonVersion}"
if (jenkins.model.Jenkins.instance.getItem("tensorflow-${operatingSystem}-${pythonVersion}") == null) {
// Create Job if it does not exists
jobDsl scriptText: createJob(operatingSystem, pythonVersion)
}
// Add Job to map of jobs to be run in parallel
builds["tensorflow-${operatingSystem}-${pythonVersion}"] = {
// Lock resource so that only a certain number of jobs can run at a time
lock(label: "tensorflow_jobs", quantity: 1, variable: "LOCKED") {
println "Locked resource: ${env.LOCKED}"
// Seed job
build job: "tensorflow-${operatingSystem}-${pythonVersion}",
parameters: [
string(name: "OPERATING_SYSTEM", value: "${operatingSystem}"),
string(name: "S2I_IMAGE", value: "${s2iImage}"),
string(name: "PYTHON_VERSION", value: "${pythonVersion}"),
]
}
}
}
}
// Run all jobs from map in parallel
parallel builds
}
} catch (e) {
echo e.toString()
throw e
}
}
// Create job
// Accepts OS and version of python
// Will generate job using jobDsl
def createJob(operatingSystem, pythonVersion) {
return """
pipelineJob("tensorflow-${operatingSystem}-${pythonVersion}") {
parameters {
stringParam("BAZEL_VERSION", "", "Version of Bazel for Tensorflow")
stringParam("CUSTOM_BUILD", "", "Custom build command for Tensorflow")
stringParam("OPERATING_SYSTEM", "", "Which Operating System is the job being built for")
stringParam("PYTHON_VERSION", "", "Version of Python to be used in the job")
stringParam("S2I_IMAGE", "", "Source 2 Image base image")
stringParam("TF_GIT_BRANCH", "", "Tensorflow branch used when checking out code")
}
definition {
cpsScm {
scm {
git {
remote { url("https://github.com/thoth-station/tensorflow-build-s2i") }
branch("*/master")
extensions { }
}
}
}
}
}
"""
}