Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-55958

Allow executing additional action in timeout step before wrapped steps will be cancelled

    Details

    • Similar Issues:

      Description

      It would be very useful to allow users to define additional steps which will be executed on timeout, but before the processes will be stopped. For example in our case we want to generate threaddump.log and dump.hprof files when the executed Java logic is frozen. It is possible to do it by using Time-out actions provided by Build Timeout plugin. Unfortunately, I cannot use it with Jenkins Declarative Pipelines.

      timeout(time: 30, onTimeout: {
          sh """#!/bin/bash
              echo "Performing thread dump"
              for pid in \$(ps auxwwe | grep APPLICATION_ID | grep -v grep | grep BUILD_ID=${env.BUILD_ID} | awk '{print \$2}'); do
                  echo "thread dump of \$pid"
                  jstack \$pid > threaddump_\$pid.log
              done
          """
      }) {
          sh "mvn verify"
      }
      

        Attachments

          Issue Links

            Activity

            agabrys Adam Gabryś created issue -
            agabrys Adam Gabryś made changes -
            Field Original Value New Value
            Description It would be very useful to allow users to define additional steps which will be executed on timeout, but before the processes will be stopped. For example in our case we want to generate {{threaddump.log}} and {{dump.hprof}} files when the executed Java logic is frozen. It is possible to do it by using {{Time-out actions}} provided by {{Build Timeout}} plugin. Unfortunately, I cannot use it with Jenkins Declarative Pipelines.
            {code:java}
            timeout(time: 30, onTimeout: {
                sh """#!/bin/bash
                echo "Performing thread dump"
                for pid in \$(ps auxwwe | grep APPLICATION_ID | grep -v grep | grep BUILD_ID=${env.BUILD_ID} | awk '{print \$2}'); do
                    echo "thread dump of \$pid"
                    jstack \$pid > threaddump_\$pid.log
                done
            """
            }) {
                sh "mvn verify"
            }
            {code}
            It would be very useful to allow users to define additional steps which will be executed on timeout, but before the processes will be stopped. For example in our case we want to generate {{threaddump.log}} and {{dump.hprof}} files when the executed Java logic is frozen. It is possible to do it by using {{Time-out actions}} provided by {{Build Timeout}} plugin. Unfortunately, I cannot use it with Jenkins Declarative Pipelines.
            {code:java}
            timeout(time: 30, onTimeout: {
                sh """#!/bin/bash
                    echo "Performing thread dump"
                    for pid in \$(ps auxwwe | grep APPLICATION_ID | grep -v grep | grep BUILD_ID=${env.BUILD_ID} | awk '{print \$2}'); do
                        echo "thread dump of \$pid"
                        jstack \$pid > threaddump_\$pid.log
                    done
                """
            }) {
                sh "mvn verify"
            }
            {code}
            agabrys Adam Gabryś made changes -
            Link This issue is related to JENKINS-19883 [ JENKINS-19883 ]

              People

              • Assignee:
                Unassigned
                Reporter:
                agabrys Adam Gabryś
              • Votes:
                1 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: