Search code examples
jenkinsjenkins-job-dsl

Script for rerunning failed builds on the matrix


I'm trying to prepare script to configure a few jobs using Jenkins Job DSL plugin. It should prepare matrix job with many axes (something around 50) and with configured option "Retry build after failure", but I noticed that it doesn't support all available options.

In job configuration (manually) we can set:

  • Rerun build for unstable builds as well as failures
  • Rerun build only for failed parts on the matrix
  • Delay before retrying build
  • Maximum number of successive failed builds

and Jenkins Job DSL has:

  • fixedDelay(int delay)
  • progressiveDelay(int increment, int max)
  • rerunIfUnstable(boolean rerunIfUnstable = true)
  • retryLimit(int retryLimit) methods.

Currently my script looks like that:

publishers {
  retryBuild {
    rerunIfUnstable()
    retryLimit(2)
    fixedDelay(0)
  }
}

Unfortunately I can't configure option: "Rerun build only for failed parts on the matrix"... It's necessary, because I don't want to rerun all parts, just because one fails.

Is it possible to do it somehow? It doesn't have to be done by Job DSL plugin (but of course not manually).

A characteristic of this project sometimes causes that some parts fail, that's why rerunning is necessary.


Solution

  • The built-in DSL does not support all options. But the Dynamic DSL does:

    matrixJob('example') {
      publishers {
        naginatorPublisher {
          regexpForRerun(null)
          rerunIfUnstable(true)
          rerunMatrixPart(true)
          checkRegexp(false)
          maxSchedule(2)
          delay {
            fixedDelay {
              delay(0)
            }  
          }
        } 
      }
    }