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
You can combine:
- the JENKINS Validating String Parameter Plugin
- a script able to validate values (independently of the plugin)
- a condition build step (with the JENKINS Conditional BuildStep Plugin/ JENKINS Run Condition Plugin)
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.
There is a workaround to this problem, using Active Choices Plugin.
Basically you need to create an Active Choice Reactive Reference Parameter without name (blank name makes the error message look like description of the parameter).
Your Active Choice Reactive Reference Parameter should:
- reference the parameter's name which you want to validate.
- have a groovy script to validate the parameter referenced.
- have set the choiceType to Formatted HTML.
Your groovy script can return the Parameter value something like this:
Valid Info Message:
return "<span style='color:green'>✅ Valid Email Id(s)</span>"
Error Message:
return """
<style>.jenkins-button--primary { display: none; }</style>
<span style='color:red'>❌ Invalid Parameter.</span>
"""
style component in this return statement vanishes the Build button.
For more information see this blog.
At the moment, the validating string parameter is the closest you'll get.
© 2022 - 2024 — McMap. All rights reserved.