2

I'm trying to setup a Jenkins server with Groovy script:

def repository = 'git@somerepo'
import hudson.tasks.Shell;

job = Jenkins.instance.createProject(FreeStyleProject, 'TestJob')
job.setDescription("Some description")
job.displayName = 'SomeTestJob(TESTING groovy)'

job.scm = new hudson.plugins.git.GitSCM(repository)
job.save()

Now I need to set a repo branch - How do I do this?

3
  • stackoverflow.com/questions/16963309/…
    – Michael Durrant
    Dec 18, 2017 at 0:00
  • def repository = 'git@somerepo' import hudson.tasks.Shell; job = Jenkins.instance.createProject(FreeStyleProject, 'TestJob') job.setDescription("Some description") job.displayName = 'SomeTestJob(TESTING groovy)' job.scm = new hudson.plugins.git.GitSCM(repository) job.scm.branches = [new BranchSpec('*/master')]; job.save() Thanks a lot Michael Durrant for giving that link ! This is strange - i've seen before but didn't manage to use the answers as i only noticed the jobDsl code fragments that time...
    – Alter_so
    Dec 19, 2017 at 8:10
  • Please post this as an answer. This Q&A pops up in the unanswered section while is has already been answered.
    – 030
    Mar 11, 2018 at 17:49

1 Answer 1

1
def repository = 'git@somerepo' 
import hudson.tasks.Shell
job = Jenkins.instance.createProject(FreeStyleProject, 'TestJob')
job.setDescription("Some description") 
job.displayName = 'SomeTestJob(TESTING groovy)' 
job.scm = new hudson.plugins.git.GitSCM(repository) 
job.scm.branches = [new BranchSpec('*/master')]
job.save()

Thanks a lot Michael Durrant for giving that link !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.