Sleep is not working in jenkins shared library

Hi, I have a pipeline using shared lib to reconnect my node agent. But the sleep commands are not working.

shared-lib:

package org.nodes

import org.nodes.NodesRepo
import org.jenkinsCore.*
import groovy.json.JsonSlurperClassic
class NodesRepoImp implements NodesRepo, Serializable{

    private env
    private steps
    private jenkinsCoreRepo
    final private nodeStatus = ['TemporarilyOffline','Disconnected','Busy','Idle']
    NodesRepoImp(env,steps){
        this.env = env
        this.steps = steps
        JenkinsCoreRepo jenkinsCore = new JenkinsCoreRepoImp()
        this.jenkinsCoreRepo = jenkinsCore
    }

    NodesRepoImp(env){
        this.env = env
    }

    NodesRepoImp(){
    }

    Boolean reconnectComputer(def computer){

        steps.retry(3){
            // exit if computer is online
            // disconnnect then connect if computer not online
            if(computer.isOnline()){
                return true
            }else{
                computer.disconnect()
                computer.connect(true)
            }
            steps.sleep(5)
            steps.echo("Checking computer status after connect")
            sleep(5)
            steps.timeout(1){
                steps.sleep(40)
                steps.waitUntil{
                    return(computer.isOnline())
                }
            }
        }
        return(computer.isOnline())
    }
}

pipeline:


@Library("shared-lib")_
// import org.testSuite.*
// import org.labels.*
// import org.versions.*
import org.nodes.*
import org.jenkinsCore.*
import org.cases.*
import org.farm.setup.*
// TestSuiteRepo testSuiteRepo = new TestSuiteRepoImp(env,steps)
// LabelsRepo labelsRepo = new LabelsRepoImp(env,steps)
// VersionsRepo versionsRepo = new VersionsRepoImp(env,steps)
FarmSetupRepo farmSetupRepo = new FarmSetupRepoImp(env,steps)
NodesRepo nodesRepo = new NodesRepoImp(env,steps)
JenkinsCoreRepo jenkinsCoreRepo = new JenkinsCoreRepoImp(env,steps)
CaseRepo caseRepo = new CaseRepoImp(env,steps)


def computer = jenkinsCoreRepo.getComputer('192.168.36.23')

println(nodesRepo.reconnectComputer(computer))

output:

10:45:28  Checking computer status after connect
10:45:28  [Pipeline] timeout
10:45:28  Timeout set to expire in 1 min 0 sec
10:45:28  [Pipeline] {
10:45:28  [Pipeline] waitUntil
10:45:28  [Pipeline] {
10:45:28  [Pipeline] }
10:45:28  Will try again after 0.25 sec
10:45:28  [Pipeline] {
10:45:28  [Pipeline] }
10:45:28  Will try again after 0.3 sec
10:45:29  [Pipeline] {
10:45:29  [Pipeline] }
10:45:29  Will try again after 0.36 sec
10:45:29  [Pipeline] {
10:45:29  [Pipeline] }
10:45:29  Will try again after 0.43 sec
10:45:30  [Pipeline] {
10:45:30  [Pipeline] }
10:45:30  Will try again after 0.51 sec
10:45:30  [Pipeline] {
10:45:30  [Pipeline] }
10:45:30  Will try again after 0.62 sec
10:45:31  [Pipeline] {
10:45:31  [Pipeline] }
10:45:31  Will try again after 0.74 sec
10:45:32  [Pipeline] {
10:45:32  [Pipeline] }
10:45:32  Will try again after 0.89 sec
10:45:32  [Pipeline] {
10:45:32  [Pipeline] }
10:45:32  Will try again after 1 sec
10:45:34  [Pipeline] {
10:45:34  [Pipeline] }
10:45:34  Will try again after 1.2 sec
10:45:35  [Pipeline] {
10:45:35  [Pipeline] }
10:45:35  [Pipeline] // waitUntil
10:45:35  [Pipeline] }
10:45:35  [Pipeline] // timeout
10:45:35  [Pipeline] }
10:45:35  [Pipeline] // retry
10:45:35  [Pipeline] echo
10:45:35  true
10:45:35  [Pipeline] End of Pipeline
10:45:35  Finished: SUCCESS


Could anyone help? :pray: :pray: :pray:

I don’t know much about the subject, the only thing that made me tick is the inconsistency there:


            steps.sleep(5)
            steps.echo("Checking computer status after connect")
            sleep(5)

One is using steps.sleep, the other one sleep.

Hi, @poddingue. Thanks for the reply. The inconsistency here is that because I want to find out whether those two forms of expression will work in the pipeline or not. Turns out none of them works in the pipeline.

1 Like

I see.

What about using Thread.sleep() ?

        steps.sleep(5)
        steps.echo("Checking computer status after connect")
        Thread.sleep(5000)

Still doesn’t work :cry: :cry: