Search code examples
jenkinsgroovyjenkins-pipelinetimeout

Jenkins pipeline : timeout in a for loop is not reset


I have a jenkins pipeline script, in which I use the Warnings Next-Generation plugin to record some issues based on some log files produced by some tasks.

For some reason, it's been some days that sometimes the job is stuck forever on one of those recordIssues task.

I surrounded the call to that recordIssues call with a timeout, itself inside a try / catch block, to give each recordIssues task a wait to end "properly".

def record_issues_map = [
    'UE4_AssetCheck' : 'DataValidation',
    'UE4_Cook' : 'DataValidation',
    'UE4_CompileBlueprints' : 'CompileAllBlueprints',
    'UE4_MapCheckValidation' : 'MapCheckValidation',
]

timestamps {
    for ( entry in record_issues_map ) {
        try {
            timeout(time: 120, unit: 'SECONDS') {
                def log_file_path = "Saved\\Logs\\${entry.value}.log"
                echo "recordIsses called for parser ${entry.key} on log file ${log_file_path}"
                recordIssues enabledForFailure: true, failOnError: true, qualityGates: [[threshold: 1, type: 'TOTAL', unstable: false]], tools: [groovyScript(parserId: "${entry.key}", pattern: "${log_file_path}", reportEncoding: 'UTF-8')]
            }
        } catch ( e ) {
            echo "Timeout during recording of issues for ${entry.key}"
        }
    }
}

But when one of those recordIssues hits the timeout, all recordIssues executed after are still cancelled because of the timeout, as you can see in the logs:

[Pipeline] timeout
Timeout set to expire in 2 min 0 sec
[Pipeline] {
[Pipeline] echo
recordIsses called for parser UE4_AssetCheck on log file Saved\Logs\DataValidation.log
[Pipeline] recordIssues
[Pipeline] }
[Pipeline] // timeout
[Pipeline] echo
Timeout during recording of issues for UE4_AssetCheck
[Pipeline] timeout
Timeout set to expire in 2 min 0 sec
[Pipeline] {
[Pipeline] echo
recordIsses called for parser UE4_Cook on log file Saved\Logs\DataValidation.log
[Pipeline] recordIssues
[Pipeline] }
[Pipeline] // timeout
[Pipeline] echo
Timeout during recording of issues for UE4_Cook
[Pipeline] timeout
Timeout set to expire in 2 min 0 sec
[Pipeline] {
[Pipeline] echo
recordIsses called for parser UE4_CompileBlueprints on log file Saved\Logs\CompileAllBlueprints.log
[Pipeline] recordIssues
[Pipeline] }
[Pipeline] // timeout
[Pipeline] echo
Timeout during recording of issues for UE4_CompileBlueprints
[Pipeline] timeout
Timeout set to expire in 2 min 0 sec
[Pipeline] {
[Pipeline] echo
recordIsses called for parser UE4_MapCheckValidation on log file Saved\Logs\MapCheckValidation.log
[Pipeline] recordIssues
[Pipeline] }
[Pipeline] // timeout
[Pipeline] echo
Timeout during recording of issues for UE4_MapCheckValidation
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Package Swarms (Win64))
[Pipeline] isUnix
[Pipeline] isUnix
[Pipeline] isUnix
[Pipeline] bat

Is there a way to circumvent that?


Solution

  • It turns out that the exception I got was not because of the timeout, but because of https://issues.jenkins-ci.org/browse/JENKINS-49732

    I replaced the for loop by record_issues_map.each { entry -> {} } to get rid of the exception.

    To solve the timeout of the recordIssues I replaced that call by a call to scanForIssues first, then publishIssues