Make Changes only to one repository, in case of Multiple SCM using Job DSL

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
    };   
    }

Answers


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')
    }
  }
}

Need Your Help

changing method using com.sun.image.* to ImageIO

java javax.imageio sun

I have a method to load an image with a filechooser and then it resize the image to a specified size to store it in the DB. i used com.sun.image.codec.jpeg.JPEGCodec and JPEGImageEncoder and i need...

What is the AMD/ATI Radeon 6000 series GPU architecture?

opencl gpu amd-processor

See question. I can find documentation on the 5000 series and 7000 series but no real notes on 6000 series. This is useful for trying to get close to the theoretical maximum throughput with OpenCL....