头图

Jenkins set task timeout⏱ (multiple methods: pictures and texts 🖼)

墨抒颖
中文

When using jenkins for automatic compilation and construction, some tasks may have been blocked due to network or other reasons, causing the project to be unable to perform compilation and construction again. We want to terminate certain tasks when their execution time exceeds a certain value.

Method one (general)

The "build timeout plugin" plugin of jenkins can help us accomplish this task. I am using jenkins-2.7.1, the plug-in is already installed by default, if it is not installed by default, you can search and install it in the plug-in management.

请添加图片描述

Method 2 (Pipeline)

Jenkins Pipeline provides a lot of steps (steps), which can be combined and nested with each other to easily solve problems such as repeating the steps until successful (retry) and exiting (timeout) if a step takes too long to execute.

pipeline {
    agent any
    stages {
        stage('Deploy') {
            steps {
                retry(3) {
                    sh './flakey-deploy.sh'
                }

                timeout(time: 3, unit: 'MINUTES') {
                    sh './health-check.sh'
                }
            }
        }
    }
}

The "Deploy" stage (stage) repeatedly executes the flakey-deploy.sh script 3 times, and then waits for the health-check.sh script to execute for a maximum of 3 minutes. If the health-check.sh script is not completed within 3 minutes, Pipeline will mark it as failed in the "Deploy" phase.

Embedded type

Embedded types of steps, such as timeout and retry can contain other steps, including timeout and retry.

We can also combine these steps. For example, if we want to retry the deployment task 5 times, but the total time spent cannot exceed 3 minutes.

pipeline {
    agent any
    stages {
        stage('Deploy') {
            steps {
                timeout(time: 3, unit: 'MINUTES') {
                    retry(5) {
                        sh './flakey-deploy.sh'
                    }
                }
            }
        }
    }
}

Series of articles

jenkins automated configuration
Jenkins's tty problem
jenkins reverse proxy configuration
jenkins's java11 issue
Jenkins private key format error problem
jenkins webhooks configuration
jenkins set task timeout⏱ (multiple methods: pictures and texts 🖼)

refer to

阅读 1.7k

前端与算法
前端与算法系列合集

msy.plus

68 声望
11 粉丝
0 条评论

msy.plus

68 声望
11 粉丝
文章目录
宣传栏