Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jenkins: pass multiple "Extended Choice Parameter" values using a URL

Tags:

jenkins

One of the parameters in my Jenkins build is an Extended Choice Parameter which is submitted as a selection of comma separated values when invoking the build from the build webpage.

However, I also need to invoke the build using wget + URL.

So, in the format:

wget "${JENKINS_URL}/job/buildname/buildWithParameters?ECP_LIST=blah1&token=token"

Say my Extended Choice Parameter ECP_LIST has possible values: blah1, blah2, blah3, blah4.

if I invoke, for example:

wget "${JENKINS_URL}/job/buildname/buildWithParameters?ECP_LIST=blah3&token=token"

the build starts fine with value blah3 for the EPC_LIST parameter.

However, if I wish to invoke it with 2 or more values, it just passes a blank value to the parameter.

I've tried separating the values using various things, like spaces, encoded comma, semi-colon. I haven't had any luck finding an answer here or on Google either.

like image 274
junebob Avatar asked Mar 24 '14 10:03

junebob


People also ask

How do you parameterize a URL in Jenkins?

Configure Jenkinsclick Add Parameter and select String Parameter. in the Name field, enter the name of the parameter that you used in the Webhook to Jenkins Job Parameters field. For each additional parameter, click Add Parameter, select String Parameter and enter the name of the next parameter. Click Save.

How do I add extended choice parameters in Jenkins?

To install this plugin, you simply need to go to your jenkins instance and navigate to “/pluginManager/available”, and then search for “Extended Choice Parameter Plug-in” in the search box. Be careful! There is another plugin called “Extensible Choice Parameter Plug-in”.

How does Jenkins pipeline pass Choice parameters?

Using build parameters, we can pass any data we want: git branch name, secret credentials, hostnames and ports, and so on. Any Jenkins job or pipeline can be parameterized. All we need to do is check the box on the General settings tab, “This project is parameterized”: Then we click the Add Parameter button.


3 Answers

I did solve it by selecting ECP_LIST multiple times:

wget "${JENKINS_URL}/job/buildname/buildWithParameters?ECP_LIST=blah1&ECP_LIST=blah2&ECP_LIST=blah3&token=token"

Will result in:

ECP_LIST=blah1,blah2,blah3

I hope that works for you.

like image 58
junebob Avatar answered Oct 28 '22 00:10

junebob


You need to encode your URL before you pass it to wget I think, if your parameters contain special chars. I do it like this in python. I use curl.

url_params = {'param1' : param_value1, 'param2' : param_value2}
params_encoded = urllib.urlencode(url_params)
params = ['curl.exe', '-v', '-X', 'POST', '--show-error', '%s?%s' % (JobUrl), params_encoded]
subprocess.check_call(params)
like image 29
Andy Chen Avatar answered Oct 28 '22 00:10

Andy Chen


Including the URL in single quotes work:

wget '${JENKINS_URL}/job/buildname/buildWithParameters?ECP_LIST=blah3&token=token'

Similarly if you want to run a curl through your Jenkins API with curl you would run:

curl -X POST 'http://api:[email protected]/job/BUILDNAME/buildWithParameters?parameter2=blah&parameter2=blahblah'
like image 4
hfranco Avatar answered Oct 28 '22 01:10

hfranco