Permalink
Browse files

Merge pull request #32 from jimmyw/feature/startOnCreate

Add possibility to start a job upon creation.
  • Loading branch information...
2 parents 53b028c + 263c266 commit 5e726a71c38db197c7891aeae6084b17a311cde3 ebakke committed Jan 14, 2013
View
@@ -33,7 +33,7 @@ task syncWithRepo(dependsOn: 'classes', type: JavaExec) {
main = 'com.entagen.jenkins.Main'
classpath = sourceSets.main.runtimeClasspath
// pass through specified system properties to the call to main
- ['help', 'jenkinsUrl', 'jenkinsUser', 'jenkinsPassword', 'gitUrl', 'templateJobPrefix', 'templateBranchName', 'branchNameRegex', 'nestedView', 'printConfig', 'dryRun', 'noViews', 'noDelete'].each {
+ ['help', 'jenkinsUrl', 'jenkinsUser', 'jenkinsPassword', 'gitUrl', 'templateJobPrefix', 'templateBranchName', 'branchNameRegex', 'nestedView', 'printConfig', 'dryRun', 'startOnCreate', 'noViews', 'noDelete'].each {
if (System.getProperty(it)) systemProperty it, System.getProperty(it)
}
@@ -61,6 +61,11 @@ class JenkinsApi {
post('job/' + missingJob.jobName + "/config.xml", missingJobConfig, [:], ContentType.XML)
}
+ void startJob(ConcreteJob job) {
+ println "Starting job ${job.jobName}."
+ post('job/' + job.jobName + '/build')
+ }
+
String configForMissingJob(ConcreteJob missingJob, List<TemplateJob> templateJobs) {
TemplateJob templateJob = missingJob.templateJob
String config = getJobConfig(templateJob.jobName)
@@ -15,6 +15,7 @@ class JenkinsJobManager {
Boolean dryRun = false
Boolean noViews = false
Boolean noDelete = false
+ Boolean startOnCreate = false
JenkinsApi jenkinsApi
GitApi gitApi
@@ -61,6 +62,9 @@ class JenkinsJobManager {
for(ConcreteJob missingJob in missingJobs) {
println "Creating missing job: ${missingJob.jobName} from ${missingJob.templateJob.jobName}"
jenkinsApi.cloneJobForBranch(missingJob, templateJobs)
+ if (startOnCreate) {
+ jenkinsApi.startJob(missingJob)
+ }
}
}
@@ -14,6 +14,7 @@ class Main {
n: [longOpt: 'nested-view', required: false, args: 1, argName: 'nestedView', description: "Nested Parent View Name - gradle flag -DnestedView=<nestedView> - optional - must have Jenkins Nested View Plugin installed"],
c: [longOpt: 'print-config', required: false, args: 0, argName: 'printConfig', description: "Check configuration - print out settings then exit - gradle flag -DprintConfig=true"],
d: [longOpt: 'dry-run', required: false, args: 0, argName: 'dryRun', description: "Dry run, don't actually modify, create, or delete any jobs, just print out what would happen - gradle flag: -DdryRun=true"],
+ s: [longOpt: 'start-on-create', required: false, args: 0, argName: 'startOnCreate', description: "When creating a new job, start it at once."],
v: [longOpt: 'no-views', required: false, args: 0, argName: 'noViews', description: "Suppress view creation - gradle flag -DnoViews=true"],
k: [longOpt: 'no-delete', required: false, args: 0, argName: 'noDelete', description: "Do not delete (keep) branches and views - gradle flag -DnoDelete=true"],
f: [longOpt: 'filter-branch-names', required: false, args: 1, argName: 'branchNameRegex', description: "Only branches matching the regex will be accepted - gradle flag: -DbranchNameRegex=<regex>"],

0 comments on commit 5e726a7

Please sign in to comment.