execute same command in multiple unix servers using Jenkins - jenkins

I have multiple Unix servers where I need to stop and start few services (name of the service are same in all servers and login user and password is also same). I am able to restart services for single unix server using Execute shell script on remote host using ssh. But not able to do for multiple servers.
Ex: Server 1 and server 2 (Both are unix servers)
script file name: sample.sh
order to run this script using Jenkins:
stop service in Server1 using sample.sh script
stop service in Server2 using sample.sh script
start service in Server1 using sample.sh script
start service in Server2 using sample.sh script
please let me know how to achieve this using Jenkins. I have done this by creating 4 job for 4 steps and then pipelined them. But in real time i have more than 10 servers and i believe this is not a good way to do.

I think your best approach would be using the Matrix Project plugin. We use it to run adminstration tasks on all nodes matching a given label in parallel.
Trivally, you can use one matrix job to stop service on all nodes and when done, trigger 2nd job to start all nodes.
It has lots of extension points defined as well.
From the notes;
You have to choose "Build multi-configuration project" when
creating a project, it can not be changed later. If you skip this
step, you will be very confused and not get very far
Each configuration is akin to an individual job. It has its own build history, logs, environment, etc. The history of your
multi-config job only shows you a list of configurations executed. You
have to drill into each configuration to see the history and console
logs.

Related

How to trigger one task present in Release Definition on multiple servers in Agent Phase?

I am using TFS 2017 update 3, In TFS 2017, I have a Release Definition in which i have a command line task thorugh which I call the cli of an automation application by passing it an arguments like below
"C:\Program Files (x86)\Auto-2019-Q1\Auto-Cli" -scriptName "Driver_Smoke.xlsx" -scriptLocation "C:\Next_Gen"
and it does run the application successfully but now i have to run the same task on multiple servers where i have already configured build agents so that the automation can be executed on multiple servers at the same time.
For this, I have added an agent phase in the release definition and have added the agent name in the demands but it works only on one server and doesn't works simultaneously on the other server.
However, I can add another agent phase option and then give the agent name of another server but then i'll have to wait for the previous agent phase task to be completed. This would take a lot of time.
I tried giving two agent.name in demands but it doesn't work like that. so, is it possible to run a task on multiple servers at the same time in release definition?
I have found one workaround for this using the existing tasks in TFS Release definition. What I did is,
I have configured two deployment agent on each server.
Copied the above mentioned cli commands into the notepad and created a batch file of it.
Created a Task in task scheduler to execute the batch file whenever the build agent service is started.
In the Release definition, once the deployment of the package is done and after which we need to run the automation using the tool, I added a Run on agent task in RD and associated one of the build agent name where i needed to run the automation tool and under the Run on agent task I added 3 tasks i.e. one to start the service and two task to stop the service, you can repeat the same set of task for multiple servers where you need to run the automation tool thorugh CI.
So, here when the deployment is done the Run on Agent task gets started and it first stops the service and then it start the service due to which the task created in tasks scheduler get triggered and the tool gets executed and then you can stop the service as you no longer need the service to run.
By using this process, i no longer need to wait for a long time except couple of seconds in order to run the automation tool on multiple servers simultaneously.

How to run a Jenkins job in other servers?

I am using digital ocean droplet.My scenarios is: I have Jenkins installed on my one server, in which I have configured the job.I want to run that job on to another server.How to achieve that?(How my Jenkins will able to ssh to another server)
If you want to execute a single command on another server - use ssh to invoke command as a build step.
If you want to run a complex job - you should configure target server as a slave and point your job to run on a specific node(slave).
Configuring slave is pretty easy, take a look at the following articles
https://wiki.jenkins.io/display/JENKINS/Distributed+builds
https://wiki.jenkins.io/display/JENKINS/SSH+Slaves+plugin

Communicate between Jenkins server without setting up master slave relation

I would like to set up jenkins server that would run test scripts based on successful build deployments on other Jenkins servers. for example, if the QA jenkins server is named JQA1OnMachine1 and i have three others that are named
J2OnMachine2, J3OnMachine3, J4OnMachine4 (different jenkins server on different boxes) can the JQA1OnMachine1 (QA jenkis) poll the others at regular interval to see if a build was deployed successfully? if so can anyone tell me how?
Jenkins master slave along with Jenkins Pipeline Plugin would be one of the better ways to implement this however, since you don't want to use that approach you can explore PSTools to remotely capture processes or files on different server.
Your builds may update a file on the build server post completion of the build and your QA machine can run script with PSTools to monitor and trigger the QA testing based on the file content

Distributed execution with Jenkins

I am working on a Robotic process automation where i need to automate 10 different process flows.Robot needs to run 24/7.My solution is hosted in AWS cloud and i have got 10 cloud machines to run the scripts.
I have a master Jenkins job which will retrieve the list of automated jobs to execute from a database and i have 10 different jobs configured in Jenkins server.Number of jobs that i need to run at the same time varies from time to time.It may be N different scripts or N instances of the same script with different data combinations.
Challenge i am facing is in post build action i am not able to control the list of scripts/jobs that i need to run based on the output from Jenkins master job.Is there any way to run only the job i need based on the output from a build command?
I was able to achieve it using Jenkins Flexible Publish plugin.

How to configure Jenkins for distributed load using multiple Jmeter-servers

I use Jmeter to generate a huge load to my web-server. Some slave machines are acted as Jmeter-server, another one - as Jmeter master that coordinates the load and collects statistics from slaves.
Now I'm trying to integrate this system to CI (Jenkins).
That's how I do it now. I have two separate Jenkins jobs: one of them prepares all slaves by running jmeter-server, another one runs Jmeter-master itself. All is fine with 2nd part: I successfully generate traffic and collect statistics. The issue is with 1st job. I have a huge set of slaves that can be rebooted anytime. So, I can't run the job that initiates jmeter-server once and forget about it. I need to run this job every time before Jmeter-master.
But in this case on some machines (that were not rebooted) I have multiple copies of java processes (jmeter-server copies).
So, I'm looking for a mechanism to start jmeter-server on slave nodes in a proper way.
Any ideas appreciated.
Thank you in advance!
Read this:
https://dzone.com/articles/distributed-performance
It combines:
JMeter
Maven Lazery JMeter plugin
Jenkins
All you have to do for jmeter-slaves is to start them from Jenkins using jmeter-server.sh , you might want to tweak port if you have 2 slaves on same host.
Then from controller you will reference those host machines (in this casse default port is used):
remote_hosts=test-server-1.nerdability.com,test-server-2.nerdability.com,test-server-3.nerdability.com

Resources