Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a Jenkins "Are you sure ..." dialog

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?

like image 462
badgerduke Avatar asked Aug 09 '13 19:08

badgerduke


2 Answers

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.

like image 70
CIGuy Avatar answered Oct 23 '22 07:10

CIGuy


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. Build parameter screenshot


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

Shell script screenshot

like image 41
Bryce Avatar answered Oct 23 '22 07:10

Bryce