multi text parameter

41 views
Skip to first unread message

Mona Pinjani

unread,
Feb 16, 2017, 6:39:34 PM2/16/17
to Jenkins Users
Hi,

I want to setup a jenkins job which takes 2 parameters which take IP addresses and host names from the user and then iterates over the IPs to run curl.

So a user can enter one ore more values for IP and VM Name.
IP=aa.bb.cc.dd  ee.ff.gg.hh (new line separated)
HOST_NAME=hostname1 hostname2 (new line separated)

I don't want this to be a choice, but rather a text entered by user. Multi line string parameter is not giving me the desired output from these parameters. What is the best way to achieve this
and iterate it ?

Thanks,

Desired output by running:
for ((i=0; i < ${#IP[@]}; i++))
do
echo "${IP[$i]} ${HOST_NAME[$i]}"
done
aa.bb.cc.dd hostname1
ee.ff.gg.hh hostname2

Instead I get this
aa.bb.cc.dd
ee.ff.gg.hh hostname1
hostname2

Mona Pinjani

unread,
Feb 17, 2017, 1:27:58 PM2/17/17
to Jenkins Users
Anyone ? What plugin should I use to get multiple values for a parameter(s) so that I can iterate over it ?
I have tried multi-line string parameter and even extended Choice Parameter. I would like the parameter values to be text based rather than choice

Victor Martinez

unread,
Feb 17, 2017, 5:28:56 PM2/17/17
to Jenkins Users
I wonder if the question is about what jenkins parameters are required (which are basically strings with some separators) or how to proceed those parameters though.

Maciej Jaros

unread,
Feb 20, 2017, 6:21:27 AM2/20/17
to jenkins...@googlegroups.com
You might want to use Groovy System Script to process those parameters (note that System script is not an OS script, it's Jenkins script). It will be much easier to process strings in it.

Here is something to get you started. This is a script that schedules "Some-job-name" to be run with some parameters. If you use string parameters you might want to trim and validate values passed by users to avoid some security/consistency problems.

// start
//--------------------------
import hudson.model.*

//
// run
//
def appServersString = build.buildVariableResolver.resolve("parameterOfCurrentJob")
def appServersList = appServersString.split(',')
for (appServer in appServersList) {
  scheduleAppRollout(appServer)
}

/**
	Schedule rollout helper
*/
def scheduleAppRollout(dstServer) {
  def job = Hudson.instance.getJob("Some-job-name")

  // prepare parameters
  def params = []
  params += new StringParameterValue('dstServer', dstServer)
  params += new BooleanParameterValue('somBooleanParamOfTheJobToBeStarted', true)
  params += new BooleanParameterValue('imABot', true)
  def paramsAction = new ParametersAction(params)

  //preapre cause
  def cause = new Cause.UpstreamCause(build)
  def causeAction = new CauseAction(cause)

  // run
  println("[INFO] Scheduling rollout to `" + dstServer + "`");
  Hudson.instance.queue.schedule(job, 0, causeAction, paramsAction) 
}
//--------------------------
// EOF

Reply all
Reply to author
Forward
0 new messages