'Abort Jenkins pipeline (workflow) build after timeout

Whenever a build gets stuck of fails somewhere the timeout kicks in but the build is not aborted and it is stuck running forever until you cancel the build, go into console and press the link Click here to forcibly terminate running steps

Here is a sample code that I'm trying but not working:

stage concurrency: 1, name: 'Build'
def buildSteps = [:]
    buildSteps['Server'] = {
        timeout(1) {
            node('build') {
                timestamps {
                     bat "waitfor nothing /t 120 >nul"
            }
        }
    }   
}

parallel buildSteps

This is the log

[Pipeline] stage (Build)
Entering stage Build
Proceeding
[Pipeline] parallel
[Pipeline] [Server] { (Branch: Server)
[Pipeline] [Server] timeout
[Pipeline] [Server] {
[Pipeline] [Server] node
[Server] Running on CI106 in C:\Jws\workspace\jftimeout
[Pipeline] [Server] {
[Pipeline] [Server] timestamps
[Pipeline] [Server] {
[Pipeline] [Server] bat
14:42:52 [Server] [jftimeout] Running batch script
14:42:53 [Server] 
14:42:53 [Server] C:\Jws\workspace\jftimeout>waitfor nothing /t 120  1>nul 
14:43:52 [Server] Sending interrupt signal to process
Aborted by user
14:49:29 [Server] Sending interrupt signal to process
Click here to forcibly terminate running steps
Terminating bat
[Pipeline] }
[Pipeline] // timestamps
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // timeout
[Pipeline] }
Failed in branch Server
[Pipeline] // parallel
[Pipeline] End of Pipeline

At 14:43:52 the timeout sends the stop signal but nothing happens.

At Aborted by user is when I manually canceled the build



Solution 1:[1]

Install Build timeout plugin https://wiki.jenkins-ci.org/display/JENKINS/Build-timeout+Plugin Go to Manage Jenkins > Configure System > Build-timeout Plugin > BuildStep Action > Check Enable BuildStep Action

After i enabled the plugin the build is stopped when timeout has reached.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 IlirB