Passing parameter in Jenkins Job - jenkins

I am setting up Jenkins job and I need to make it parametrized such that it can take below parameters and pass it to my build script.
Parameters -
Entry point: E1/E2 (default : E1)
Protocols: ABC, DEF, … (default : all)
Build script :
cd ${WORKSPACE}/myworkSpace
mvn clean install -P **E1** -Dformat.type=**ABC**
mvn clean install -P **E2** -Dformat.type=**DEF**
I tried with $Parameter but it dint work for me. Please suggest what is correct approach to do this parametrization.

From your comments, I understand that you have defined two parameters from the UI, and you were able to add a default value.
entry_point=E1
format=ABC
In your build's UI, you have a "Execute Shell" section, to re-use these parameters:
cd ${WORKSPACE}/myworkSpace
mvn clean install -P $entry_point -Dformat.type=$format
When executed with the default commands, it will produce the following command:
mvn clean install -P E1 -Dformat.type=ABC
Your variable name does not need to be in uppercase. But the name should be identical.
If you need more details about the fancy usage of this awesome plugin, you can have a look there:
https://wiki.jenkins.io/display/JENKINS/Parameterized+Build

Related

Jenkins: Goals and options in Maven plugin

In Jenkins config, we have Goals and options, against which we add the path of .xml file which we have to execute. Like:
clean test -DpathToMySuiteFile_1=sanity.xml
In above line, what is the work of -D?
It is connected with Maven (and Maven plugin), not Jenkins itself.
-D option is used to define system properties for Maven via command-line, e.g.:
mvn clean test -Dproperty1=propertyValue2 -Dproperty2=propertyValue2
So, in your case, -D just sets sanity.xml value to DpathToMySuiteFile_1 variable.
This option is usually used to customize the behavior of Maven plugins. See details here.
Update: as #snukone already mentioned, here is the detailed answer.

Run Newman in jenkins

this is my first time using Jenkins for automated test.I've tried to run a test by integrate Newman with Jenkins but I always get the
Console Error
"Newman : command not found"
as a result,it's make my test failed.
I have looking for some answers on the Internet and some tell me to add a value for Environment variables, but I don't know how to get the exact value to add to this. Please show me where can I get this.I'm using MacOS High Sierra
Install https://plugins.jenkins.io/nodejs in jenkins
In Global Tool Configuration add Nodejs and in "Global npm packages to install" add newman
In Build Environment use "Provide Node & npm bin/ folder to PATH"
In Build add "execute shell" if you are using linux or use "execute windows batch command" if you are on windows and add your newman command
For example:
newman run
https://www.getpostman.com/collections/631643-f695cab7-6878-eb55-7943-ad88e1ccfd65-JsLv
the html extra reporter only worked for me once enabling 'locate executor' and flag "with ant" as well, under the provide node & npm option.
I had the similar problem. I had several lines of the text in the Command field. According to advice I used backslashes to make it look pretier and I couldn't create a report with Newman. I got a report only after deleteing the backslashes and writing all information in one line

Jmeter+Jenkins Parameters

I am trying to run jmeter(.jmx) file using Jenkins by passing Number of Threads as a Parameter. Build getting success but .jmx file is not running. And also not showing any error in console.Following are my setup
In Jmeter Thread properties --Number of thread (Users)- ${__P(USERS,1)
In Jenkins job Created build string parameter -- USER_COUNT
Build using Execute shell and following is my command
cd /apache-jmeter-2.13/bin
./jmeter.sh -n -t /jmxFiles/Jbpm6Rest3Jenkins1.jmx -l /jmxFiles/SIP.jtl -JUSERS=%USER_COUNT%
While starting build passing USER_COUNT value from Jenkins
Following is the Jenkins console output
Jenkins Console Output
Not sure where i am doing wrong.
Note: Not using Ant/Maven to run jmx file.
As the other answer mentioned, change the %_USER_COUNT% to ${USER_COUNT}.
But is there any specific reason you are not using Ant/Maven?
Eventhough you should be able to run your jmeter test using a simple shell script, using Ant/Maven might make your life easier while generating report, charts etc.
I would advise you check the below links.
http://www.testautomationguru.com/jmeter-continuous-performance-testing-part1/
http://www.testautomationguru.com/jmeter-continuous-performance-testing-part2/
From the output, seems you are running a shell build step ($ /bin/sh -xe ....), which means your Jenkins runs on Linux (?). Also the paths use forward slash (/)....
You should put the string ${USER_COUNT} as part of your command (%USER_COUNT% is windows style).
I hope this helps.

Pass a dynamic parameter in Jenkins build

I want to pass a dynamic parameter in Jenkins in a scheduled job (this build runs every day at 3:00 am)
This works if I executed it in my linux command line:
mvn package -DintegrationTag=$(date +%d-%m-%y)
or
mvn package -DintegrationTag="$(date +%d-%m-%y)"
or
mvn package -DintegrationTag="$(date +"%d-%m-%y")"
with these 3 options this is what is executed, for example (this is what I want to do in Jenkins):
mvn package -DintegrationTag=16-09-2013
but any of these sentences, do not work in my Jenkins goals and options (because the dynamic parameter).
Is there any way to do it?
The solution:
Content of the file which constains the script:
echo "NOW=`date +%d-%m-%y`"> env.properties
Path of the properties file:
env.properties
In project, goals and options:
clean test package -DintegrationTag=$NOW
Inject environment variables to the build process = true
In a Build "execute shell" section add this
NOW=`date +%d-%m-%y`
mvn package -DintegrationTag=$NOW
Another option can be to execute a top level maven target in jenkins.
The first two steps of injecting the required variable value into the build environment remains same as the answer given by #Iker below.
In the third step, give goal as
clean test packageand then in Properties section within the 'Advanced' tab, giveintegrationTag=$<your variable name>
Note that this solution is useful when one creates a free style project in jenkins. For maven 2/3 projects,solution by #Iker is good:)

Jenkins: how can I add -D parameter to the build?

How can i make Jenkins do the following:
When i create a WAR file i normally run the following command:
mvn clean install -Dapp.env=SOME_ENVIRONMENT
Which loads the specific properties for that environment. I've added a build parameter in Jenkins, but this has had no effect.
When you add a new job or modifying an existing job you can put this directly into Goals and options under 'Build':
clean install -Dapp.env=SOME_ENVIRONMENT

Resources