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();
  }
}

AnyStatus ‘support for Jenkins MultiBranch’

Two weeks ago I came across a plugin for Visual Studio; AnyStatus. It gives you the ability to keep track of all kinds of services/servers while working in Visual Studio. It lacked the ability to track Jenkins MultiBranch projects, what we use a lot at my work; Soltegro. Since the API was straightforward and freely available in GitHub, I decided to develop it myself. And as of this week it has been merged into the Plugins dll; Pull Request 4.

The code could use some extra work, when the API introduces a better way for managing and creating sub-items. There is still discussions going on about this; Issue 2.

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.