snippetgitMinor
How to set a Git repository when creating a job in Jenkins from a Groovy script?
Viewed 0 times
scripthowcreatingjenkinsgitrepositorywhenfromjobset
Problem
I'm trying to setup a Jenkins server with Groovy script:
Now I need to set a repo branch - How do I do this?
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?
Solution
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 !
Code Snippets
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()Context
StackExchange DevOps Q#2917, answer score: 1
Revisions (0)
No revisions yet.