Last active
September 16, 2024 18:27
-
-
Save aespinosa/6bd1b8d2d65aed2179de to your computer and use it in GitHub Desktop.
create a jenkins job in the script console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jenkins.model.Jenkins; | |
import hudson.model.FreeStyleProject; | |
import hudson.tasks.Shell; | |
job = Jenkins.instance.createProject(FreeStyleProject, 'job-name') | |
job.buildersList.add(new Shell('echo hello world')) | |
job.save() | |
build = job.scheduleBuild2(5, new hudson.model.Cause.UserIdCause()) | |
build.get() # Block until the build finishes | |
generatedJobs = build.getAction(javaposse.jobdsl.plugin.actions.GeneratedJobsBuildAction).getItems() | |
# FIXME skip .scheduleBuild2() on Folder jobs | |
generatedJobs.each { j -> j.scheduleBuild2(5, new hudson.model.Cause.UserIdCause()) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Responding to an ancient post with hopes of some direction :o)
Needing to create a new branch using the beginnings of the script below (I need to use script like this). I am needing scm.??? for 1) complete a checkout and 2) push to origin (in script).
Many thanks in advance.
[Manual Git Steps that do what I need]
// CHECK-OUT - To create a new branch and switch to it, use git checkout -b <branch_name>.
git checkout -b release-dev master
// CHECK-IN
git push origin release-dev
[Partial Synthesis]
import hudson.util.RemotingDiagnostics
import jenkins.model.Jenkins
import hudson.plugins.git.GitSCM
def scm = new GitSCM("https://someurl/api/v3/repos/HPEFS/don-test")
scm.branches = [[name: "*/release-dev"]]