Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins - How to run one housekeeping job on all nodes (slaves + master)

Tags:

jenkins

I have Jenkins setup of 6 Slaves and master, all windows machines. Now I have a housekeeping Jenkins job which I want to periodically run on all the slaves and master, as this job does following tasks

  • Delete unused temporary files.
  • Delete unwanted processes, as some of the tests are leaking processes (why leak is different question).
  • Set certain environment variables, as sometimes I want to push environment variable changes to all machines.

Any idea how can I force Jenkins to run this one job on all slaves and master once every day? As a work around I can create multiple Jenkins job and mark each one to run on one particular slave or master, but I would rather avoid having so many duplicate jobs.

like image 638
Hemant Avatar asked Feb 12 '15 21:02

Hemant


3 Answers

The Node and Label Parameter plugin allows you to parameterize where a job should be run. The job can be run on more than one node -- each node shows up as a separate execution in the job's build history. When multiple nodes are selected, you can configure whether the job should continue to run on other nodes if an execution fails.

like image 56
Dave Bacher Avatar answered Sep 22 '22 08:09

Dave Bacher


I had a similar need, but using the Node and Label Parameter Plugin didn't seem quite right, as I do not want to parameterize my cleanup jobs.

I found a more satisfying answer in this post and thought it would also benefit to this question: Jenkins - Running a single job in master as well as slave.

Here is some documentation on how to configure a "Matrix project": https://wiki.jenkins.io/display/JENKINS/Building+a+matrix+project.

What you are looking for is the "Slave axis". It's not very well documented in the page above, but it appears as an option of the "Add axis" menu whenever there are more than one node. Here's a screenshot of the interesting part:

Configuration matrix using the slave axis

like image 27
Jonathan Avatar answered Sep 18 '22 08:09

Jonathan


Updates according to recent Jenkins

enter image description here

Pipeline type: enter image description here

On "Configuration" page for pipeline:

enter image description here

like image 40
Zam Avatar answered Sep 21 '22 08:09

Zam