Parameterize Performance Build in Jenkins - jenkins

I am new to jenkins. I am trying to moniter performance test for my project.
I have my scripts in Jmeter.
I have created paarmeterize job in jenkins as shown.
Threads: 1
RampUp: 1
Loop: 40.
I am using backend listner to check data in Grafana and Appdynamics.
Now when i start the build the scripts run only once, but i am expecting script must run for 40 times (With build success).
But when i run it through jmeter, scripts run for 40 times succesfully. (Some issue with jenkins i suppose)
Please suggest how can i resolve the issue in jenkins as my project requeiremnt needs it to run script from jenkins.
Thank you in advance!

It's hard to say what's wrong without seeing your Jenkins job and JMeter Thread Group configuration.
In order to apply external settings in JMeter you need to define threads, ramp-up and the number of iterations using JMeter Properties via __P() function like:
Once done you will be able to override the values of these properties using -J command line argument, for example in Jenkins:
jmeter -Jthreads=1 -Jrampup=1 -Jloops=40 -n -t test.jmx -l result.jtl
This way you will be able to pass whatever number of virtual users/iterations without having to change your script.
More information: Apache JMeter Properties Customization Guide

Related

Can Jenkins run some code or it is only scheduling external programs?

I'm new to Jenkins and I heard it is really good for continues integration.
My flow is not complicated: I need to get a list from SQL by some query, parse it line by line, send each line to some virtual machines (which will run this line and create some file as result), and then analyze the results.
Where in Jenkins can I program my code?
Is Jenkins' purpose is only to schedule external programs one by one and not to run the code in Jenkins itself?
Is there a way to write code in jenkins that is not a bunch of CMD commands?
you can do the following ( syntaxic pipline ) :
- stage 1 : execute command over ssh (jenkins plugin) to execute sql query
- stage 2 : send each line to dedicated VM with Ansible playbook
- stage 3 : analyze depend on the tech you are using there are plenty of jenkins plugin to connect to monitoring and analyzing tools like grafana or zabbix .. that can ease the process
I think what you are asking for is scripted pipeline: https://jenkins.io/doc/book/pipeline/
This allows you to write Groovy code to execute on the Jenkins master. You can do almost anything you want from there, just like any programming language.

how to deploy Drupal with Jenkins only if the tests are successful

I have some doubts about the correct configuration of Jenkins to ensure the continuous integration of a Drupal project but I arrive at some contradictions.
Let me explain: the deployment, after all, consists in executing:
cd / path / to / web / root
pull from git
drush config:import
drush cache:rebuild
The tests are launched with the command
../vendor/bin/phpunit --verbose --log-junit ../tests_output/phpunit.xml -c ../phpunit.xml
The contradiction is that I do not understand when to run the tests.
Before the pull does not make sense because the last changes are missing, after the pull if any test goes wrong I should be able to restore the situation before the pull (but I'm not sure it's a safe action).
I'm trying to run the tests directly in the workspace of jenkins and to do this I also created a separate database, but at the moment I get the error:
Drupal\Tests\field_example\Functional\TextWidgetTest::testSingleValueField
Behat\Mink\Exception\ElementNotFoundException: Button with id|name|label|value "Log in" not found
What could be the best strategy to follow?
So, your order seems ok - pull first then run tests.
However, you can have 2 Jenkins jobs. First runs, your tasks. 2nd runs ONLY if your first job completes without failure.
There are ways to get exit status from scripts - see following plugins/notes about that.
How to mark Jenkins builds as SUCCESS only on specific error exit values (other than 0)?
How to mark a build unstable in Jenkins when running shell scripts

How to start Owasp zap server(exe or jar) from jenkins

Actually, the main issue is if I start the server then my next commond will never trigger as it always running as zap server in listening mode.
Can I run two command line in Jenkins. I have added 2 "Execute Windows batch command" still nothing works. I have added the image in same thread
I have tried by creating a batch file
cd /
cd C:\Program Files\OWASP\Zed Attack Proxy
start java -jar zap-2.6.0.jar
I am getting error as below after using above batch file
Process leaked file descriptors. See https://jenkins.io/redirect/troubleshooting/process-leaked-file-descriptors for more information
https://wiki.jenkins.io/display/JENKINS/Spawning+processes+from+build
I have also use command line arugument directly in "Execute window batch command" like:-
java -jar zap-2.6.0.jar
But the UI of zap is not starting
I have also tried "Windows Exe Runner Plugin"
https://wiki.jenkins.io/display/JENKINS/Windows+Exe+Runner+Plugin
But jenkins not allowing me to put an exe name in configuration. Looks like a bug of jenkins.
I have also tried by adding zap in environmental variable but that also not working.
Now I am out of idea.
The issue is if I am triggering zap.bat it will do not allow another command to run forward as below which is in my batch:-
Additionally, UI of zap is not open as it is open after direct clicking on zap.bat file
I have added 2 "Execute Windows batch command" still nothing works
Any suggestions will be welcome
Simple - dont start it from the jar!
Start it using the zap.sh or zap.bat scripts we provide as part of the installation :) You'll also probably want to use the -daemon flag.
Or you can use the official ZAP jenkins plugin: https://wiki.jenkins.io/display/JENKINS/zap+plugin
I have resolve this issue by creating two jobs in jenkins.
The main job trigger the first job.
Follow the steps :-
Go to the configure section of main job
Now add "Trigger/call builds on other projects" from Build option
Add the project name of zombie job
Note :- uncheck the checkbox of "Block until the triggered projects finish their builds".

Is it possible to access Jenkins build status in execute shell?

Is there a way to have a script being run from an execute shell step access the build status as well as other information about the build? (e.g. build number, start/end time, etc)
I need to update a wiki page with a script with the information about the build.
Thanks in advance!
Build status information gets saved into simple XML files. Take a look at
{jenkins-directory}/jobs/{job-name}/builds/{build-number}/build.xml. You can use symbolic links like lastSuccessfulBuild instead of specifying a build number if you want.
You'll find all information about the build there: build status, start time, duration, etc. Parse the XML file or just use grep in a bash script.
If you don't want to use the filesystem you can use Jenkins API.
But in any case, once you got a script that can determine build parameters and update your wiki page, you can put it into another Jenkins job and trigger it automatically (for example, with the BuildResultTrigger Plugin).
I'm using jenkins own API to get the build status while the job is running, which works like a charm. Be aware that i'm using JQ To parse the json response.
To get this to work simply add a shell script and execute the following command: BUILD_STATUS=$(curl --silent ${BUILD_URL}api/json | jq -r '.result')
Which results in the following:
While executing a build, Jenkins set environment variables you can use in your script.
also refer to the detailes on how to use it -
%VAR% in batch files and $VAR from inside the Jenkins job configuration page

Script to build a set of jobs, wait until they finish and write a report about them

I'm planning to write a script that would choose a set of Jenkins jobs with a regexp, start their builds and wait until they finish. If most of them fail, I want to change some global env vars (I already know how to do this) and build them again. Then I want to collect the test results and format it into a nice report.
I can't put this into the individual jobs' post-build actions, I need info about all of them to write the report and to do the rebuilding.
My current idea is to use the Jenkins REST API, but before I do so: is this already implemented somewhere?
Give a look at Multi-Job plugin and see if it fits your requirement.
Else go with REST API.
Because unique requirement of our build process I had to use jenkins cli :
java -jar jenkins-cli.jar -s http://<jenkinsURL> build <job-name> -s <parameters if any>
The trailing -s makes it wait till the job is complete.

Resources