Run batch file located on another machine - jenkins

I have Jenkins installed on my machine. I have a batch file which is located on another machine and I want to run it in my Jenkins job.
What steps are required to do this?

If you want to run the batch file on the other machine, the solution is to split your job in 2 jobs:
One running on your machine
The second running on the other machine to launch your batch file
The other solution is to store your batch file in SVN or Git, and to pool it on your machine with your Jenkins job.

Related

How to automatically copy artefacts from Jenkins job into given network drive?

I'd like the files generated by Jenkins script to be automatically copied into a given directory on the local network.
Is there a plugin or script for doing that ?
In my case it worked by using SCP in a build step "Execute shell". The remote server needs to be accessible via ssh.
If your artifacts are the result of a maven build, maybe a Nexus Repository Manager is what you are looking for. A simple mvn deploy would do the job.

How to create single Jenkins project for run in multiple platforms

My Jenkins server has multiple slaves with different platforms (Windows, Linux and Mac). I need to run a job in each slave to copy a network folder to each local machine. Here are few questions I have.
Can I create a single project with Batch, bash, Mac bash script and add condition to execute.
Can I create multiple project for each platform and add condition to run depends on the platform.
Is there any use of Multi-configuration project for this situation
What is the best way to achieve this
I would look at using a configuration management tool such as Chef or Puppet, which provides a platform independent DSL to do operations such as copying files. You could then set up a multi-configuration job in Jenkins to run the same job on each of the different slaves.
The simplest way is to create a job in Jenkins that will archive the network folder each time something changes in it, and use the Copy Artifact Plugin to take it to the workspace of each slave wether it is Linux or Windows.
Simple, elegant :)

running a powershell script on multiple servers using Jenkins

I have a situation where I need to run a clean up script written in powershell on Multiple servers , say around 100 windows servers.
How do I accomplish this ?. Doing thru SSH would be cumbersome I believe . I am looking for a better way to configure the Jenkins job to get this task done.
Regards
Raj
First Solution
Install a Jenkins agent on all your Windows machines
Affect the same label on all these Windows nodes
Next, you have to install the Matrix Project plugin and create a multi-configuration job.
You have to configure the matrix to run your job on the specific label:
This job will execute your Powershell maintenance script on all the Windows nodes.
Here is a screen copy of a similar maintenance job I'm running on my CentOS nodes:
Second solution (not tested)
The second solution (using OpenSSL) is to execute your Powershell script remotely:
https://hodgkins.io/automating-with-jenkins-and-powershell-on-windows-part-2

Running a build on Jenkins Slave

I have done the following
Create a slave Node
In the Labels field added Test
Save the node configuration
Created a new Job
Selected the options Restrict where this project can run
In the Label expression field added Test
Save the job
When i build the job, i get the error
java.io.FileNotFoundException: C:\Users\Administrator\Test\src\test\java\test\data\Project Suites.xlsx (The system cannot find the path specified)
Not Sure whats wrong, The folder does not exist in the slave machine but exist in the Master machine.
But if i run it using the master it works fine.
Hmm I dont understand the problem - you said it yourself, the file does not exist in the slave machine, and you're running jenkins on the slave. So of course its not going to find the file?
Just move the file to the slave machine and run the job on the slave?

Build a project remotely but pick the code from local machine through Jenkins

I'm running jenkins on my local machine. I need to build and run a project on remote machine as a slave.
I have my project(Java code) in my local machine where the Jenkins is running. So Now when I build the project it looks for the code in my slave machine and says it's not able to find the build.xml in my slave machine.
I want to be able to have Jenkins looks for the code in my local machine and build it in my slave machine and run in the slave machine.
Is that possible? if yes pls help me.
You do not state which version control system you are using? Jenkins has version control plugins for Git, Subversion, etc...
The idea is that you commit and push your changes to your source code repository and the Jenkins slave will automatically pull down the code and compile if anything has changed.
Try the copy artifact plugin. You can create 2 jobs - 1st one to just check out the source code from your repo/version control/workspace. The second job (which runs on the slave restrict where this job can be run inside the job config) can copy those files automatically to the ...remote slave/workspace and then you do whatever you want with them.
This will do what you want, but as Mark O'Çonnor mentions, the idea is you commit the changes to your repository and then the other machine checks it out.

Resources