0

I am creating a new job in Jenkins by copying a template job. For a template with single repository I am using the below code to change the branches to build section.

job('example') {
  using('template_job')
  configure { node ->
    node / scm / branches / 'hudson.plugins.git.BranchSpec' {
      name 'branchname'
     }
  }
}

But now my template job has multiple respositories and I have to change the branches to build for just one of the repositories using a Configure Block. How can I achieve this.

I have tried the below code as well.Its not working, no changes are done. Will any modification of this work?

 configure {node ->
    node / scm/ 'hudson.plugins.git.GitSCM'[1]  / branches / 'hudson.plugins.git.BranchSpec'{ 
    name branchName1
    };   
    }
shwetha
  • 376
  • 4
  • 7
  • 22

1 Answers1

0

The / operator only returns the first child with a given name. You need to assign the intermediate node to a variable and then use the groovy.util.Node API to access any child. From then on, you can use the / for navigating again. The example below modified the second SCM config, the index starts at zero.

job('example') {
  using('template')
  configure { node ->
    def scms = node / scm / scms
    scms.children()[1] / branches / 'hudson.plugins.git.BranchSpec'{ 
      name('foo')
    }
  }
}
daspilker
  • 8,154
  • 1
  • 35
  • 49