简体   繁体   中英

Inject Configuration into multiple Jenkins jobs via DSL

I have a number of maven project in Jenkins and I would like a mechanism where i can inject a piece of configuration into all of them at once.

or example if I decide to change the logRotation.

I found this can be done via the DSL plugin, but I so far I am only able to inject one project at a time.

mavenJob('EXAMPLE_TEST1') {
    publishers {
         textFinder(/There are test failures/, '', false, false, true)
   }
}

The above works and inject a piece of config for the textFinder plugin into a maven project

How do i achieve the same for EXAMPLE_TEST2, 3, 4, 5, 6 etc

Appreciate any help

I decided to go a little further and create an array of all jobs in Jenkins

import hudson.model.*

allTests(Hudson.instance.items)


def allTests(items){
def list = []

for (item in items) {
  def name = item.getName()

  if (name.contains("API")){
  } else {
    list << item.getName()
 }
}

list.each { job ->  

mavenJob("${job}")
{
publishers {
    textFinder(/There are test failures/, '', false, false, true)
   }
  }
 }
}

Sorry for the above format

So this will now grab every job in Jenkins that does not contain the text API and add it to an array and will inject the configuration required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM