-
Notifications
You must be signed in to change notification settings - Fork 17
/
create-seed-job.groovy
90 lines (83 loc) · 2.81 KB
/
create-seed-job.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
import jenkins.model.*
def jobName = "SeedJob"
def git_url = System.getenv('SEEDJOB_GIT')
def svn_url = System.getenv('SEEDJOB_SVN')
def scm = '''<scm class="hudson.scm.NullSCM"/>'''
if ( git_url ) {
scm = """\
<scm class="hudson.plugins.git.GitSCM">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<url><![CDATA[${git_url}]]></url>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>**</name>
</hudson.plugins.git.BranchSpec>
</branches>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<submoduleCfg class="list"/>
<extensions/>
</scm>
"""
} else if ( svn_url ) {
scm = """\
<scm class='hudson.scm.SubversionSCM'>
<locations>
<hudson.scm.SubversionSCM_-ModuleLocation>
<remote><![CDATA[${svn_url}]]></remote>
<local>.</local>
<depthOption>infinity</depthOption>
</hudson.scm.SubversionSCM_-ModuleLocation>
</locations>
<workspaceUpdater class='hudson.scm.subversion.UpdateUpdater'></workspaceUpdater>
<excludedRegions></excludedRegions>
<includedRegions></includedRegions>
<excludedUsers></excludedUsers>
<excludedCommitMessages></excludedCommitMessages>
<excludedRevprop></excludedRevprop>
</scm>
"""
}
def configXml = """\
<?xml version='1.0' encoding='UTF-8'?>
<project>
<actions/>
<description>Create Jenkins jobs from DSL groovy files</description>
<keepDependencies>false</keepDependencies>
<properties>
</properties>
${scm}
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders>
<javaposse.jobdsl.plugin.ExecuteDslScripts plugin="job-dsl@1.37">
<targets>**/*.groovy</targets>
<usingScriptText>false</usingScriptText>
<ignoreExisting>false</ignoreExisting>
<removedJobAction>IGNORE</removedJobAction>
<removedViewAction>IGNORE</removedViewAction>
<lookupStrategy>JENKINS_ROOT</lookupStrategy>
<additionalClasspath></additionalClasspath>
</javaposse.jobdsl.plugin.ExecuteDslScripts>
</builders>
<publishers/>
<buildWrappers/>
</project>
""".stripIndent()
if (!Jenkins.instance.getItem(jobName)) {
def xmlStream = new ByteArrayInputStream( configXml.getBytes() )
try {
def seedJob = Jenkins.instance.createProjectFromXML(jobName, xmlStream)
seedJob.scheduleBuild(0, null)
} catch (ex) {
println "ERROR: ${ex}"
println configXml.stripIndent()
}
}