Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fast fail Jenkins Build Flow Plugin job?

Tags:

jenkins

I'm trying to fail a Build Flow Plugin job if a parameter isn't set. When I try:

final parameter = params['PARAMETER']
if (parameter.isEmpty()) {
  out.println('Error: PARAMETER must be defined')
  System.exit(1)
}

the entire Jenkins master dies (double plus ungood).

How do I get the job to fail without killing Jenkins?

like image 322
Noel Yap Avatar asked Jan 09 '23 17:01

Noel Yap


1 Answers

Set the Result on build.state then return so as not to execute anything else:

import hudson.model.Result

final parameter = params['PARAMETER']
if (parameter.isEmpty()) {
  out.println('Error: PARAMETER must be defined')
  build.state.setResult(Result.FAILURE)
  return
}
like image 117
Noel Yap Avatar answered Jan 16 '23 04:01

Noel Yap