2

I want to perform a reboot on Windows 7 and 10 computers but I first need to put the Jenkins nodes temporarily offline. Before I perform the reboot, I need for any running tasks to finish. Then I login remotely into the servers and restart the computers. Before I restart the computers however, I need to make sure that there is enough space in the computer. If there is more than 75% of the space occupied, I need to delete files that are dated long ago. After clearing up some space, I restart the computers. I wait until the restart is finished and then put nodes back online.

This is the task I am trying to automate using a script. How can I script this? I am currently manually doing these steps but I want to try and automate it. I was thinking of using Powershell in restarting the computers but I am not sure how to actually do it.

treatyoself
  • 83
  • 2
  • 16

1 Answers1

3

Instead of doing everything in powershell, you could make a job, running only on master, and dedicated to reboot a node server.

You have a similar idea implemented in the Jenkins inodes monitor plugin (to be adapted to your case)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for the way to go about this. I'm relatively new to Jenkins so in the newer version (2.60.1), how would I create this job and only run it on the master? – treatyoself Jun 06 '19 at 04:12
  • 1
    @treatyoself 2.60 seems an old version (the latest LTS is 2.164.3: https://jenkins.io/changelog-stable/) But in any way, you can restrict a job to a node: https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/: `node(master)` would be enough to set it to `master` only, using pipeline syntax: https://jenkins.io/doc/book/pipeline/syntax/. – VonC Jun 06 '19 at 04:40
  • I see, but I want to make this simple where I just run one script and it takes the nodes temporarily offline, wait for the node to be idle, checks whether or not there's enough space on the server, clears up old files or directories, restarts the computer, then puts the nodes back online. Is there any way to do this with just one script? – treatyoself Jun 08 '19 at 21:23
  • @treatyoself Not sure, but on the "takes the nodes temporarily offline", that is what saferestart does: https://stackoverflow.com/a/26219545/6309 – VonC Jun 08 '19 at 22:18