-
Notifications
You must be signed in to change notification settings - Fork 1
/
createPipelineJob.groovy
30 lines (26 loc) · 1.24 KB
/
createPipelineJob.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
import hudson.plugins.git.*;
import groovy.json.JsonSlurper
// Example json configuration for jobs (this should be in a repo)
def restResponse = '''[
{"url":"[email protected]:dermeister0/Tests.git", "branch":"*/master", "pipelineName":"tes1"},
{"url":"[email protected]:dermeister0/Tests.git", "branch":"*/master", "pipelineName":"test2"},
{"url":"[email protected]:dermeister0/Tests.git", "branch":"*/master", "pipelineName":"test3"},
{"url":"[email protected]:dermeister0/Tests.git", "branch":"*/master", "pipelineName":"test4"}]'''
// Parse the response
def list = new JsonSlurper().parseText( restResponse )
// Creating each pipeline
list.each {
scmURL = it['url']
scmName = null
scmRefspec = null
scmCredential = 'jenkins-credential'
scmBranch = it['branch']
jenkinsfileName = "Jenkinsfile"
pipelineName = it['pipelineName']
def scm = new GitSCM([new UserRemoteConfig(scmURL, scmName, scmRefspec, scmCredential)], [new BranchSpec(scmBranch)], false, null, null, null, null)
def flowDefinition = new org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition(scm, jenkinsfileName)
def parent = Jenkins.instance
def job = new org.jenkinsci.plugins.workflow.job.WorkflowJob(parent, pipelineName)
job.definition = flowDefinition
parent.reload()
}