22

I would like to implement the following in a job : When we click on the "Build" button of a parametrized build, the user will get a prompt/popup asking if they would like to perform the build or not. If, The answer (yes/no) then the build runs - otherwise not.

Are there any pointers to relevant documentation on how to do this ? Any plugins doing anything similar I am already using the Parameterized build, I want this when we click on the Build button not prior to that, as we have a Choice parameter in the build, and I need the user always select the correct choice from the drop down. Please help, I did not get anything related to this till now. The other options are to use a Boolean parameters / choice for yes / no, I was thinking more along the lines of a popup or confirmation like before erasing a job , there is an "are you sure" prompt. Any idea how to implement that kind of confirmation message ?

Vaibhav
  • 353
  • 1
  • 2
  • 7
  • Hm..sounds strange. The users needs first to click on build button than has to give some answers and afterwards needs to click on Build button ? Why do you need a supplemental yes/no ? does not make sense to mee. – khmarbaise Feb 28 '14 at 11:42
  • 2
    I have a job which deploys the code / files to different environments, i.e. DEV, QA, UAT, PROD. So I want that the user who clicks on Build after selecting to environment to confirm his selection before the build actually triggers. Else, If someone selects UAT / PROD by mistake in place of DEV / QA there will be consequences. Let me if there is a way to achieve this. – Vaibhav Mar 01 '14 at 11:21
  • 1
    I had a similar use-case last year, but was unable to find an out-of-the-box solution, and creating custom plugin for it, seemed like a high price. :( In the end, I ended up separating the critical (UAT/PROD) jobs from the regular and locking down who could initiate as-well as allow me to cancel an erroneous build before anything bad happened, by putting in an 30 second quite period and including the environment in the build-name. – tveon May 15 '14 at 14:01
  • 2
    Have you considered using a promotion for this? You could create two jobs: one to build (which also archives) and another to deploy. The first would have a promotion that requires the environment parameter and triggers the second with that parameter. The second can copy the artifacts from the first and, using the environment parameter, deploy things to the right place. – JZimmerman May 30 '14 at 18:29

2 Answers2

17

Add a parameter to the build. You could just name the parameter "Are you Sure?".

Eduardo Souza
  • 201
  • 2
  • 8
  • One draw back: a browser may be configured to remember form input and auto-fill the confirmation input. Another solution may be the [build with parameters (and confirmation) plugin](https://wiki.jenkins-ci.org/display/JENKINS/Build+With+Parameters+Plugin). Yet another solution may be to use [custom Javascript](https://wiki.jenkins-ci.org/display/JENKINS/Simple+Theme+Plugin). – bishop Aug 25 '15 at 13:57
  • 1
    Unless you use a different plug-in from mine, this doesn't really prevent building, but just adds a confirmation box. I prefer using something which actually needs an action (other than a mindless click) from the user. See my answer for such an example (I guess for a real error-proof build, you could even ask for a precise string to be manually typed. Not the kind of thing to put on a daily build, of course, but definitely great to prevent mistakes on production environnements – Balmipour Jun 07 '16 at 19:59
3

Jenkins has a conditional-buildstep plug-in designed for this. It probably has a few other dependencies, but it seems the plug-in manager automatically handles this detail.

Once installed :
• Add a select parameter to your build
• Add a condition to cancel your build or put your conditions on the specific steps you want to enable conditionnally
• profit.


Step 1 :

Build the condition definition


Step 2 :

Check the condition

°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
Here's the official page :

Balmipour
  • 2,985
  • 1
  • 24
  • 28
  • Ok, this works but: In the advanced options you cannot say to fail on "evaluates to false". You can only choose to fail if you cannot evaluate it, for example the parameter does not exist. This makes it so each and every buildstep has to be a conditional buildstep. – JerMah Feb 22 '19 at 15:17