Space separated string parameter in Jenkins String Parameter - jenkins

I have a string parameter in jenkins called 'Keywords'.
I set the value of Keywords = "Google,Microsoft,Uber Go".
But jenkins string parameter takes only till "Google,Microsoft,Uber" and truncates "Go" automatically.
Due to this my code runs incorrectly.
Can anyone help in handling this auto-truncate issue in jenkins string parameter?
This string parameter is used in my python code where I split the Keywords on comma(,) and use the 3 generated words for operation in my code. But jenkins is truncating "Go" automatically due to which incorrect word is processed by my code.

Found the solution for this.
While calling the string parameter variable "Keywords" put in Double quotes. Shell script command to be put in Jenkins :
python script.py "${Keywords}"

Related

DSL Jenkins pass parameter to phaseJob

On Groovy DSL how can I use jenkins parameters in a phaseJob name.
When trying to do
stringParam('jobName', 'bla', 'blabla')
...
phaseJob('$jobName')
jobName is not replaced with the value I entered in Jenkins
You are using single quotes. As you can read here
Any Groovy expression can be interpolated in all string literals, apart from single and triple single quoted strings.
You need to use double quotes in order to make "string ${interpolation}" work:
phaseJob("$jobName")

JMeter: more than nine parameters from Jenkins

I am trying to pass more than nine parameters from Jenkins to JMeter4.0.
As I was reading, I found out that JMeter does not accept more than 9 parameters. As a workaround, I want to pass all the parameters as a string and split it in JMeter BeanShell.
java -jar -Xms512m -Xmx2048m C:\JMeter4\bin\ApacheJMeter.jar -Jjmeter.save.saveservice.output_format=csv -Jjenkinsparams="%Timetorun%,%Users%" -n -t %JMeterPath%\bin\tests\tests.jmx -l %WORKSPACE%\Results.csv
The tests run on a Windows machine. From this call I have
jenkinsparams = "300,2"
I use a BeanShell PreProcessor like this:
String line = "${__P(jenkinsparams)}";
String[] words = line.split(",");
vars.put("timetorun",words[0]);
vars.put("users",words[1]);
log.info(words[1]);
log.info(users);
I tried few log.info to check the values. For words[1] I have the correct value sent from Jenkins: 2. For the users the value displayed is: void.
I am trying to use it for Number of Threads as: ${__P(users,1)}.
What am I doing wrong? The values clearly arrive from Jenkins but I have a problem passing it to my variable. Thank you
You don't have a script variable named users, so you should either log words[0]:
log.info(words[0]);
Or you can log the value of JMeter variable called users:
log.info(vars.get("users"));
Or you can assign words[0] to variable called users:
String users = words[0];
log.info(users);
Also you are saving it as variable, not property, so you can retrieve it elsewhere in script as
${users}
The syntax __P refers to property, so if you want to use it as property, you need to change how you are saving it:
props.put("users", words[1]);
If you do that, ${__P(users,1)} should work
Now, if you want to use this value as number of threads, then you need to do this:
Have Setup thread group with 1 thread, and your script
In the script you must save users as property, otherwise it won't pass between threads
Next thread group then can use it as number of threads
As long as your command line fits into 8191 characters it should not be a problem to pass as many arguments to JMeter as you want, here is an evidence from Debug Sampler and View Results Tree listener combination
So keep calm and pass as many parameters as needed via -J command line arguments.
Be aware that starting from JMeter version 3.1 users are recommended to use JSR223 Test Elements and Groovy language instead of Beanshell so going forward please consider switching to Groovy.

How to assign values from groovy to a Jenkins parameter name with space?

I have multiple jobs which have a string parameter build called " Release Context". I have coded some groovy script to automate the process, trigger the jobs and pass the parameters. But I am having some issues to escape the space in the name of parameter:
def params = [new StringParameterValue( 'Release Context' , paramValue)]
def paramsAction = new ParametersAction(params)
jobs.scheduleBuild2(0, paramsAction)
The code works fine; the jobs are triggered and the values are passed when I replace the name with Release_Context but not when it contains space. Somehow I am restricted to not change the name of parameter therefore I need some help to escape the space. I have tried some ways with (/) or double (") but didn't give any result. Thank you in advance!

Jenkins Remote Parametrized build always uses default parameter values instead of those that are passed

I have a Jenkins job that has a single boolean parameter. The default value of this parameter is false. I remotely build it from an ANT build script (of another job) by POST'ing to the build URL and passing my token and parameter.
curl -X POST 'MY_JENKINS_SERVER/job/JOB_NAME/buildWithParameters?token=12345;REPORTS=true' --user MY_USERNAME:MY_PASS
Note that I have the URL enclosed in single quotes (which should take care of encoding issues) and that the name of the boolean parameter is REPORTS (capitalized in Jenkins and in ANT). Also, I'd like to note that if I use an ampersand (&) to separate the token and my other parameter I get the following error when building: The reference to entity "REPORTS" must end with the ';' delimiter.
No matter what the value of the REPORTS parameter is in the URL string, the parameter is always the default value of false when it goes to build. I changed the default value to true in Jenkins and it is always true regardless of the passed parameter value. Basically, it always uses the default value and ignores the passed parameter value. I've also tried passing no REPORTS parameter and of course it takes the default value.
In my job's build file (the one that I am triggering remotely), I print the parameter as ${env.REPORTS}
I've looked over similar questions on SO, but none of their solutions work for me. I've tried moving the parameters around in the URL and nothing seems to work. Any ideas?
Based on this line:
The reference to entity "REPORTS" must end with the ';' delimiter
Instead of &, try &
This is not an issue with Jenkins, but with Ant which is an XML file. Since & is a special character for XML, in order to have a plain value of & anywhere, you need to write it as &

Jenkins' String parameter vs Text parameter

In a parameterized Jenkins job, what is the difference between String Parameter and Text Parameter? I don't even see a mention of Text Parameter in the documentation
Text parameter was added in Jenkins, but it didn't exist in Hudson (at least in the past)
Main difference is that the Text parameter supports multi-line, while the String one doesn't
Update
Here is the original ticket that requested this functionality
https://issues.jenkins-ci.org/browse/JENKINS-5577
It doesn't look like something that was designed for Jenkins. Rather someone asked for it, and then someone said they have an implementation available. Kohsuke added it to main Jenkins, but from what I've read, it's quite buggy.
Using string parameter can deliver full string value, while multi-line string parameter not if your string value is too long.
Jenkins ver. 2.73.1.

Resources