How should I validate Jenkins build parameters on the front-end to enable/disable the build button?

Alex Brodov picture Alex Brodov · Jul 18, 2016 · Viewed 7.7k times · Source

I have complex jobs with a lot of parameters, is there any way to validate those parameters using JavaScript form validation or with some other methods, and if the user's input isn't not correct, i'll show an error message and also disable the build button. I've tried installing the Validating String Parameter Plugin , it seems like that it's only displaying errors

Answer

VonC picture VonC · Oct 23, 2017

You can combine:

That way:

  • the validating String parameter plugins prevents users to enter invalid values
  • the script (written in any language you want) will validate those parameters again, but this time called as a "Script Condition", to decide if a step should be executed or failed.

That ensures that, even if the job is called directly through API (without any string validation from the first plugin), the script (called by the second conditional step plugin) will block/fail the job if its execution (validating the strings/parameters by script) does end with a failure status.