4

I have a requirement to call a parameter based on user input for another parameter. In short,

I have a parameter for build_type with choice values Daily, Release and Snapshot. Only whenever user selects Snapshot option for build_type, it should prompt user to enter snapshot name.

Do we have any plugin for this ?

Thanks, Ras.

Ras
  • 543
  • 1
  • 9
  • 25

1 Answers1

7

Give this a try https://wiki.jenkins.io/pages/viewpage.action?pageId=74875956
Its straight forward you can also try this https://wiki.jenkins.io/display/JENKINS/Extended+Choice+Parameter+plugin

EDITED
It does work, you just have to do a bit of groovy scripting :)

First you need to select Active Choice Parameter enter image description here

Then select Active Choice Reactive reference Parameter

enter image description here

Groovy script

   if(States.equals("Snapshot")){
inputBox="<input name='Snapshot' type='text' >"
}

TA-DA enter image description here

I'll leave the beautification/formatting to you :)

Community
  • 1
  • 1
rohit thomas
  • 2,302
  • 11
  • 23
  • I tried that, there is no option for user entry. It prompts the user with options defined inside the job, and it matches the defined parameters dynamically. But, snapshots are not static and I could not assign them to any parameter. It must be user entry. – Ras May 31 '18 at 17:36
  • Thank you Rohit. Will give it a try today. – Ras Jun 04 '18 at 19:54
  • Unfortunately I could not test this due to a bug in configuration/plugin https://issues.jenkins-ci.org/browse/JENKINS-51719 – Ras Jun 06 '18 at 02:02
  • @RasDama I think you need to add the whole stacktrace there ....plus this looks like a similar issue https://issues.jenkins-ci.org/browse/JENKINS-36361 – rohit thomas Jun 06 '18 at 03:15
  • Starting with Active Choices v2.0, sandboxed Groovy scripts for Active Choices Reactive Reference Parameter will no longer emit HTML that is considered unsafe, such as – Ras Jun 18 '18 at 22:44
  • I see only radio buttons, single select, multi select and checkboxes options under choice type. – Ras Jun 18 '18 at 22:46
  • Do you have admin privileges ?? If you do, go to Manage Jenkins, Under that In-Process Script Approval you need to approve this plugin features ...generally you will face these kinds of issue because it's not a widely used plugin and there might be security issue hence the added check...And don't except much support from the plugin as it's no longer available in Jenkins update center...If feasible, create your own plugin, will give you much better control and you wont have to worry about these issues :) – rohit thomas Jun 19 '18 at 02:45
  • No pending classpath entry approvals. Classpath entries already approved: No approved classpath entries. – Ras Jun 19 '18 at 05:00
  • Did you get the latest plugin for Active Choices Reactive ?? – rohit thomas Jun 19 '18 at 15:58
  • Hi Rohit, I have V2.1 – Ras Jun 19 '18 at 20:23
  • 1
    I downloaded the same one ... and it's available there ....Did you select Active Choices Reactive Reference Parameter or Active Choices Reactive Parameter because the former has `Formatted HTML` and the latter doesn't :) – rohit thomas Jun 20 '18 at 02:39
  • Thank you so much Rohit. My bad, I have selected, Active Choices Reactive Parameter. Now I have changed it to "Active Choices Reactive Reference Parameter", Looks good now. Thank you so much. – Ras Jun 20 '18 at 17:08
  • No issues... happy to help :) – rohit thomas Jun 21 '18 at 02:20
  • Could you please suggest the syntax for reading this HTML variable naming "Snapshot" in pipeline. Tried these, params.Snapshot, ${Snapshot}, $Snapshot but none of them is working. Kindly help. – Tanul Apr 22 '20 at 19:46
  • @Tanul States is the variable and Snapshot is one of the values of States.... – rohit thomas Apr 23 '20 at 05:35
  • @rohit, in the image above can we get that zzzz value in pipeline. Is there anyway to read that textbox – Tanul Apr 23 '20 at 09:11
  • @rohitthomas, hi, i'm also trying to fetch the user inputs (like "zzzz") to use it from groovy or shell step, but i can't get it. it's possible ?? – Adir Dayan Jun 23 '20 at 09:46
  • try using inputBox `inputBox="` – rohit thomas Jun 23 '20 at 10:37
  • @rohitthomas, after i press build, i still can't find any argument as 'inputBox' or 'Snapshot' in the other Groovy/Shell Build Step. maybe you can see more details for my issue here - https://stackoverflow.com/questions/62532153/how-to-get-user-inputs-from-jenkins-active-choice-parameter-using-formatted-html – Adir Dayan Jun 23 '20 at 11:18
  • @Tanul - hi, you was able to reach such "zzzz" value from user inputs ? – Adir Dayan Jun 23 '20 at 15:15
  • @AdirD, Any success getting the input value? – guymi Sep 01 '20 at 05:46
  • @guymi, yes :) follow this answer - https://stackoverflow.com/a/62541190/6130501 – Adir Dayan Sep 01 '20 at 08:50
  • @rohitthomas Can you please advise on how can I ignore `.env` (dotenv) file in jenkins, it would be really help >> https://stackoverflow.com/questions/65284867/how-can-i-ignore-the-actual-dotenv-env-file-while-running-in-jenkins – soccerway Dec 16 '20 at 03:21