-
-
Save aespinosa/6bd1b8d2d65aed2179de to your computer and use it in GitHub Desktop.
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()) } |
Now, how to create a groovy build step? Specifically a system groovy build step? I'm not a java developer and google isn't helping me.
is there a way I can add the SCM section in this script? something like:
job.buildersList.add (new GitSCM'repo.git'))
or what would be the right sintax for this request?
@djgio02 you can figure it out by looking at the javadocs of the git-scm jenkins plugin.
I spent some time trying to figure out the SCM part, I am adding a comment here so it may help someone in the future:
import jenkins.model.Jenkins
import hudson.model.FreeStyleProject
import hudson.model.Label
import hudson.tasks.BatchFile
import hudson.plugins.git.GitSCM
import hudson.plugins.git.BranchSpec
def scm = new GitSCM('https://github.com/tlopo/WinAppDriver-Sample.git')
scm.branches = [new BranchSpec("*/master")]
command = """
powershell -Command npm install -g appium
powershell -Command reg add "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1"
powershell "Start-Process 'cmd' -ArgumentList '/c \\"C:\\Program Files (x86)\\Windows Application Driver\\WinAppDriver.exe\\" 127.0.0.1 4723/wd/hub 1>winappdriver_out.log 2>winappdriver_err.log' -WindowStyle Hidden
.\\mvnw.cmd test
"""
job = Jenkins.instance.createProject(FreeStyleProject, 'winappdriver-poc')
job.setScm scm
job.buildersList.add(new BatchFile(command))
job.setAssignedLabel( Jenkins.instance.getLabel('win'))
job.save()
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"]]
Thank you so much! This is way way simpler than using XML, APIs, or the whole Job DSL plugin syntax. I don't understand why there are not more examples like this online.