Skip to content

Instantly share code, notes, and snippets.

@CedricGatay
Created August 21, 2012 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CedricGatay/3416073 to your computer and use it in GitHub Desktop.
Save CedricGatay/3416073 to your computer and use it in GitHub Desktop.
Jenkins : quick create job and vm for feature branch
import hudson.model.FreeStyleProject
import hudson.model.Result
import hudson.plugins.copyartifact.CopyArtifact
import hudson.plugins.git.BranchSpec
import hudson.tasks.BuildTrigger
def featureName = "feature"
def branchName = "origin/feature/mybranch"
def jenkins = jenkins.model.Jenkins.instance
FreeStyleProject templateNightly = jenkins.getItem("template-branch");
def jobNightly = jenkins.copy(templateNightly, "branch-"+featureName)
jobNightly.disabled = false
jobNightly.scm.branches= [new BranchSpec(branchName)]
def noSpacefeatureName = featureName.replaceAll(" ", "_");
FreeStyleProject templateVagrant = jenkins.getItem("template-vagrant")
def jobVagrant = jenkins.copy(templateVagrant,"vagrant-"+noSpacefeatureName)
jobVagrant.disabled = false
jobVagrant.builders.find {it instanceof CopyArtifact}.each { CopyArtifact copyArtifact ->
copyArtifact.projectName = "branch-"+featureName
}
jobVagrant.save()
jobNightly.getPublishersList().add(new BuildTrigger([jobVagrant], Result.UNSTABLE));
jobNightly.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment