5

We have script that use vSphere to do revert-snapshot to machine and turn on.

And then we check if agent available like this:

    def checkAgentAvalability(agName, tolerance) {
    try {
        int sleepTime = 5
        def jenkinsObj = Jenkins.instance.getNode(agName)
        printLogger("INFO", "checkAgentAvalability()  Agent: " + agName + ", tolerance: " + tolerance)
        handleSlaveMode(agName, false)
        sleep (5000)
        for (int i = 0; i < tolerance; i++) {
            if (jenkinsObj.toComputer().isOnline()) {
                if (jenkinsObj.getRootPath() != null && !jenkinsObj.getComputer().getLog().contains('error'))
                {
                    return true
                } else {
                    sleep (5000)
                }
            }
            sleep (5000)
        }
        return false
    }
    catch (err)
    {
        return false
    }
}

We use this scripts to get up 30 machines and prepare them for tests.

We are getting failures with random machines with this exception:

java.io.NotSerializableException: hudson.slaves.JNLPLauncher

How its possible to fix this issue? I can't find the root cause in internet.

How its possible to check if agent that created automatically is up? We also sometimes have disconnects after agent is up

Thanks

Zakk
  • 758
  • 3
  • 11
  • 20

2 Answers2

0

You should use the @NonCPS annotation. In general, Jenkins assumes that all objects are serializable, since it would like to pause/resume jobs. If they are not (as for example Computer) they need some special metadata so Jenkins would know that.

@NonCPS
def checkAgentAvalability(agName, tolerance) {
    try {
        ...
hakamairi
  • 4,464
  • 4
  • 30
  • 53
0

If you inline your variable jenkinsObj, the heap will be serializable. Serialize will be call on every sleep in jenkins w/o NonCPS annotation. You also may set the jenkinsObj variable to null before calling "sleep" an get it again after sleeping

def checkAgentAvalability(agName, tolerance) {
try {
    int sleepTime = 5
    printLogger("INFO", "checkAgentAvalability()  Agent: " + agName + ", tolerance: " + tolerance)
    handleSlaveMode(agName, false)
    sleep (5000)
    for (int i = 0; i < tolerance; i++) {
        if (Jenkins.instance.getNode(agName).toComputer().isOnline()) {
            if (Jenkins.instance.getNode(agName).getRootPath() != null && !Jenkins.instance.getNode(agName).getComputer().getLog().contains('error'))
            {
                return true
            } else {
                sleep (5000)
            }
        }
        sleep (5000)
    }
    return false
}
catch (err)
{
    return false
}
Jan H.
  • 1