Jenkins “ghost” slaves

I use Jenkins a lot at work. We have quite an expansive setup; tens of agents and hundreds of jobs. We run specific jobs on specific agents based on labels. For a while we had some labels show up on our Labels Dashboard that we’re listed as having no Jobs, but one slave; a “ghost” slave. However when going into the page of the specific label the agent/slave was not showing anything. 

After some investigating with some Groovy script through the console I found there exists a slave in the configuration without a computer. To remove it (and resolve my label issues) I ran the following script:


for (slave in Jenkins.instance.slaves) {
  if (slave.getComputer() == null) {
    println(slave)
    Computer computer = slave.createComputer();
    computer.setTemporarilyOffline(true,null);
    computer.doDoDelete();
  }
}

Jenkins ‘Build back to normal’

Yesterday, I finished porting our Jenkinsfile to use the new Declarative syntax. It makes the flow of processing a lot more straightforward and it’s great for handling errors and post actions. However getting everything to work again was tricky!

I was looking to send an e-mail and Office365 notification when a build returns to normal. Others updated the status of the current build during their steps, as seen on stackoverflow and here. I managed to do it slightly different without having to manage the current state;

pipeline {
  agent any
  post {
    success {
      script {
        if (currentBuild.getPreviousBuild().getResult().toString() != "SUCCESS") {
          echo 'Build is back to normal!'
        }
      }
    }
  }
}

For more details on the syntax of declarative pipelines, I’d recommend this site.

Update on 2012 resolutions…

Ok, I must confess it has been a while since I last posted. In my last post I talked about resolutions for 2012 and now I would like to give that an update. In some way I’ve worked on all of them.

In September I switched jobs, to a much smaller company; Soltegro. It gives me much more ways to grow and improve myself and bond with my colleagues. It is also a tad bit closer to home, and I can safely work from home so the commute is a lot better, giving me more time off. Instead of using that time for working on personal projects as I promised I’ve taken a second job working on mobile-, media- and games-applications. During that job I have however developed my first android app that went online in the Google Play store; MMH Calculator.

I’ve spent the spare time between my two jobs working on my prototype. It isn’t as far as I had hoped, but I’ve got 3 more weeks with some days off until the end of the year, so who knows?