I have some Jenkins jobs which affect production servers. It would be nice to have an "Are you sure you want to do this?" dialog when a user runs one of these jobs. I have not found a plugin for this. Has anybody out there tried to do this?
You could add an "Are you sure?" Parameter to the build. When a user hits "Build Now" they will be asked to enter the parameter, which could be a choice "Yes/No" or string. You could then check this parameter via a shell or batch step and "exit 1" if it is not set to Yes.
I have implemented this exact feature on our Jenkins instance. The way I have accomplished this is by using the "This build is parameterized" feature to add a build parameter that can be used to determine whether commands should be run.
On the job configuration page, select "This build is parameterized", then Add Choice Parameter (you can also use any other type of parameter, just update the IF statement below as appropriate). Enter a name (no spaces or special characters), choices of no and yes (top one is default), and an optional description.
Now you can add an "Execute shell" build step that checks the value of AreYouSure to see if you want to go through with executing the full build. If the value is not "yes" then exit with code 1 so Jenkins reports a build error. All steps below the check will not be executed if the user did not select "yes".
Here is the code to check the variable value:
if [ "${AreYouSure}" = "yes" ]
then
##commands to execute
else
exit 1
fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With