How to set jenkins string parameter in Windows batch command - jenkins

I have declared a string parameter in Jenkins i.e "Year".
The value is to be set in windows batch command, because i thought this was simple without a plugin.
Below screen depicts on how i am setting the parameter Year.
When I do echo can see in the console correct data is displayed however when I try to use the same parameter after this execution in next set as ${params.Year}, it seen as empty.
What I am doing wrong here? not able to figure it out.

Related

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.

Jenkins Extended Choice Parameter - using the values

I'm new to Jenkins so this is probably an easy one. I have the Extended Choice Parameter plugin installed. I'm using the Multi Select parameter type to pick from a list of servers (SERVER1,SERVER2,SERVER3) I've set Source for Value, Default Value, and Value Description.
I save it, and it looks great. I can pick any or all servers for the build. Now for the big question.. how do I use these values in the build? Basically I have a step in the build that can take in a comma separated list that is called by a shell command:
d:\python\deploy.py?serverlist=$blah
What do I put in for $blah to use that list of servers?
Just to be clear, if I'm on command line I would do the following:
d:\python\deploy.py?serverlist=SERVER1,SERVER2,SERVER3
I'm sure it's something simple but I just cannot find it in the docs or an example.
We could get the servers list like this
d:\python\deploy.py?serverlist=$SERVERLIST
or this on Windows
d:\python\deploy.py?serverlist=%SERVERLIST%
To see the list of environment variables which we could you, try this URL (change localhost by your Jenkins URL, TEST by the job name, 10 by the build number)
https://localhost:8080/job/TEST/10/injectedEnvVars/
UPDATE to #sniperd's edition:
This URL will shows us the parameters list in the Job:
http://localhost:8080/job/TEST/59/parameters/

Is there a jenkins plugin to add a why-I-built-this remark, that will appear with 'started by [user]'?

When I run a manual build, I'd often like to mark it with documentation to show why I ran it. Is this feature available with a plugin?
thank you!
I would approach this by adding a build parameter as a string, as above, then use the Description Setter Plugin to set it from that parameter. We use something like this for the regex:
^\++ : BUILD DESCRIPTION : GERRIT_CHANGE_OWNER_EMAIL=([^#\s]*)\S*, BUILD_USER_EMAIL=([^#\s]*)\S*, GERRIT_BRANCH=(\S*), GIT_COMMIT=(\S{8}).*$
and this for the description:
\1\2, \4, \3
As a result we get:
jspain, 0ee3198b, master
or when it fails, we get:
Failed due to timeout.
wayvad, fc7bdf2a, master
this "Failed..." text comes from the Build Timeout Plugin
I am not aware of a plugin that can do this, and after a brief search I could not find one to do what you describe.
You can mimic this behavior by adding a string parameter in the job that takes a default value of automatically started when it's normally run, but that you can change to my reasons for this build when starting it manually.
You could then use a batch (or groovy or ) build step to print the contents of that parameter into the build log. If you do some sort of SCM checkout I'm not sure how close you can get it to print to the line that contains the username that started the job, however you can click on the view parameters button in the job build and see what was in the field quickly without having to parse the logs.
The downside of this is that parameter would have to be added to each job.

Powershell Parameter Passing

This seems so trivial, but I can't figure out why the parameters I'm passing into a .ps1 script from the command pane aren't getting captured correctly as shown in this image below. String parameters are just empty, numbers are 0 which tells me I've overlooked something basic! This is with Powershell v2.
Thanks mklement0.
It was, in fact, a path issue within the ISE

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 &

Resources