How to prevent Jenkins from reconnecting to the slave after one or two attempts if slave is unreachable

12 просмотров
Перейти к первому непрочитанному сообщению

Алексей Селезнёв

не прочитано,
2 окт. 2017 г., 11:17:4102.10.2017
– Jenkins Users
I've just met some problem with slave creation.
I need to create slave machines on demand, so
I'm creating DumbSlave as follow:

    def createJenkinsNode() {
        def sshCredentials = settings['jenkins']['ssh_credentials']

        SSHLauncher launcher = new SSHLauncher("10.1.1.10", 22, sshCredentials, "", "", , "", "")

        def dumbSlave= new DumbSlave(
            "some_name",
            "/home/jenkins",
            launcher
        )
        dumbSlave.numExecutors = 1
        dumbSlave.mode = Node.Mode.EXCLUSIVE
        dumbSlave.labelString = 'some_label'
        dumbSlave.retentionStrategy = new RetentionStrategy.Always()

        Jenkins.instance.addNode(dumbSlave)
    }
After that, I can use it in my pipeline and run some commands:

    ....
    stage("Build") {
        node("some_name") {
            echo "Running on the slave machine"
            sh "sleep 50"
        }
    }

Everything works fine until the slave goes offline or something happens with the network connection during the job execution. If this happens, Jenkins's infinitely trying to reconnect to the slave, but if slave or connection never come back, the job is stuck forever.

One solution that comes to my mind is to wrap the code inside "stage" block in "timeout" block:

    ....
    stage("Build") {
        timeout(1) {
            node("some_name") {
                echo "Running on the slave machine"
                sh "sleep 50"
            }
        }
    }

I don't like this approach because I have to specify timeouts instead of event handling.
I believe something could be done with the help of `RetentionStrategy.Demand()` but I'm not sure.

How can I stop the job if Jenkins is not able to connect to the slave after one or two attempts?

Question on stackoverflow.com:
https://stackoverflow.com/questions/46521492/jenkins-stop-trying-to-reconnect-to-the-slave-if-it-is-offline
Ответить всем
Отправить сообщение автору
Переслать
0 новых сообщений