How to fix an instance having an invalid identity.key.enc file?

Article ID:215578778
1 minute readKnowledge base

Issue

  • Agent starting log contains this exception:

<===[JENKINS REMOTING CAPACITY]===>channel started
Slave.jar version: 2.53.2
This is a Unix agent
Evacuated stdout
ERROR: Unexpected error in launching a agent. This is probably a bug in Jenkins.
java.lang.NullPointerException
	at org.jenkinsci.main.modules.instance_identity.InstanceIdentity.getPublic(InstanceIdentity.java:118)
	at org.jenkinsci.modules.upstart_slave_installer.SlaveInstallerFactoryImpl.createIfApplicable(SlaveInstallerFactoryImpl.java:30)
	at org.jenkinsci.modules.slave_installer.SlaveInstallerFactory.createIfApplicable(SlaveInstallerFactory.java:29)
	at org.jenkinsci.modules.slave_installer.SlaveInstallerFactory.createFor(SlaveInstallerFactory.java:46)
	at org.jenkinsci.modules.slave_installer.impl.ComputerListenerImpl.onOnline(ComputerListenerImpl.java:30)
	at hudson.slaves.SlaveComputer.setChannel(SlaveComputer.java:558)
	at hudson.slaves.SlaveComputer.setChannel(SlaveComputer.java:366)

Environment

  • CloudBees Jenkins Enterprise

  • SSH Build Agents plugin

Resolution

This issue can happen when identity.key.enc is corrupted, empty or deleted.

To resolve it, follow this procedure:

  • stop the Jenkins instance

  • on the Jenkins server, remove $JENKINS_HOME/identity.key.enc and $JENKINS_HOME/secrets/org.jenkinsci.main.modules.instance_identity.InstanceIdentity.KEY files

  • start the Jenkins instance

These files will be recreated automatically upon startup on recent Jenkins version. If it’s not the case, you can force that by running this Groovy script in Script Console:

def keyDecorator = new org.jenkinsci.main.modules.instance_identity.PageDecoratorImpl()
jenkins.model.Jenkins.instance.getExtensionList(hudson.model.PageDecorator.class).add(keyDecorator)