Jenkins- How do i run a batch command on Master in a job that runs on a slave

1.5k Views Asked by At

I'm trying to a run a simple windows batch command (say copy) on Master inside a job that's set to run on a particular slave.

What i'm trying to accomplish with this is that copy the build log that gets saved on a master to a shared drive that's accessible from master. Please advise.

2

There are 2 best solutions below

1
On

You are going to have to make the jenkins file system visible on the client independently of Jenkins. Since you have a Windows client, you are probably going to have to setup sharing from the Jenkins master using samba or something of the sort.

What I do instead: When I need assets from master is I use curl or wget to download the assets to the clients. You can use the FSTrigger plugin to start builds when the file changes on the Jenkins master. Once curl or wget has run, your asset is then in the %WORKSPACE% directory and you can proceed.

0
On

I would recommend to handle the logfile copying (and maybe further tasks) as a dedicated job (let's call it "SaveLog"). SaveLog should be tied to run only on master. You should then configure SaveLog to be triggered after completion of your primary job. The Logfile is already available on master, even if you do not save any artifacts.

Should you need further files from the slave workspace, then you should save them as artifacts. SaveLog (on master) can then still decide whether to do anything useful with those artifacts.