Skip to content

[JENKINS-17116] graceful job termination #14386

Closed

Description

@jenkins-infra-bot

Using the freestyle projects to execute bash shell scripts work fine. But cancelling a jenkins job seems to use SIGKILL. In this way the script cannot perform cleanup operations and free resources.

SIGKILL cannot be handled by shell

SIGINT/SIGTERM are not used by jenkins

Preferred: SIGINT -> wait 5 seconds -> SIGKILL


Originally reported by markusb, imported from: graceful job termination
  • status: Resolved
  • priority: Major
  • component(s): core
  • resolution: Fixed
  • resolved: 2019-10-07T06:38:48+00:00
  • votes: 38
  • watchers: 52
  • imported: 2025-11-24
Raw content of original issue

Using the freestyle projects to execute bash shell scripts work fine. But cancelling a jenkins job seems to use SIGKILL. In this way the script cannot perform cleanup operations and free resources.

SIGKILL cannot be handled by shell

SIGINT/SIGTERM are not used by jenkins

Preferred: SIGINT -> wait 5 seconds -> SIGKILL

  • environment: any

Activity

  1. jenkins-infra-bot commented on Mar 7, 2013

    @jenkins-infra-bot
    Author
  2. jenkins-infra-bot commented on Apr 17, 2013

    @jenkins-infra-bot
    Author
    deepchip:
    • Original comment link
    • Raw content of original comment:

      I created this freestyle job, but the traps are never invoked when hitting [x] to "stop" the job.

      #!/bin/bash
      echo "Starting $0"
      echo "Listing traps"
      trap -p
      echo "Setting trap"
      trap 'echo SIGTERM; kill $pid; exit 15;' SIGTERM
      trap 'echo SIGINT; kill $pid; exit 2;' SIGINT
      echo "Listing traps again"
      trap -p
      echo "Sleeping"
      sleep 10 & pid=$!
      echo "Waiting"
      wait $pid
      echo "Exit status: $?"
      echo "Ending"
      

      It looks like Jenkins is using kill -9, but it is not since the rest of the script is executed:

      Listing traps
      Setting trap
      Listing traps again
      trap -- 'echo SIGINT; kill $pid; exit 2;' SIGINT
      trap -- 'echo SIGTERM; kill $pid; exit 15;' SIGTERM
      Sleeping
      Waiting
      Build was aborted
      Aborted by d'Anjou, Martin
      Build step 'Groovy Postbuild' marked build as failure
      Recording test results
      Exit status: 143
      Ending
      

      Is it possible that Jenkins disables the traps?

    I created this freestyle job, but the traps are never invoked when hitting [x] to "stop" the job.

    #!/bin/bash
    echo "Starting $0"
    echo "Listing traps"
    trap -p
    echo "Setting trap"
    trap 'echo SIGTERM; kill $pid; exit 15;' SIGTERM
    trap 'echo SIGINT; kill $pid; exit 2;' SIGINT
    echo "Listing traps again"
    trap -p
    echo "Sleeping"
    sleep 10 & pid=$!
    echo "Waiting"
    wait $pid
    echo "Exit status: $?"
    echo "Ending"
    
    

    It looks like Jenkins is using kill -9, but it is not since the rest of the script is executed:

    Listing traps
    Setting trap
    Listing traps again
    trap -- 'echo SIGINT; kill $pid; exit 2;' SIGINT
    trap -- 'echo SIGTERM; kill $pid; exit 15;' SIGTERM
    Sleeping
    Waiting
    Build was aborted
    Aborted by d'Anjou, Martin
    Build step 'Groovy Postbuild' marked build as failure
    Recording test results
    Exit status: 143
    Ending
    
    

    Is it possible that Jenkins disables the traps?

  3. jenkins-infra-bot commented on Apr 17, 2013

    @jenkins-infra-bot
    Author
    deepchip:
    • Original comment link
    • Raw content of original comment:

      Making this a major issue because there is no way a free style job can clean up after itself.

    Making this a major issue because there is no way a free style job can clean up after itself.

  4. jenkins-infra-bot commented on Apr 19, 2013

    @jenkins-infra-bot
    Author
    torbent:
    • Original comment link
    • Raw content of original comment:

      I am struggling with this as well! There is documentation which states that Jenkins uses SIGTERM to kill processes, but I too am having a hard time trapping it. One of the problems I have is that even if my script might trap the TERM, Jenkins appears to not wait for termination of the process(es) it has started. It's a bit difficult, then, to know whether the traps work or not when I cannot see the output.

      You should be aware that the bash build scripts are usually invoked with -e, which may "break" your error handling. Jenkins will list all of the processes you have started, including the sleep, and send a TERM to all of them. Your sleep then fails (before you can kill it), causing the rest of the script to fail. It looks like you may have worked around that to get the "Ending" text out, but it caught me and may confuse others trying to reproduce the problem The "list all of the processes" part involves an environment variable called BUILD_ID. See https://wiki.jenkins-ci.org/display/JENKINS/ProcessTreeKiller

      By using a set +e (and maybe BUILD_ID=ignore – so many experiments lately) I have managed to make my script ignore TERM, which can consistently lead to an orphaned bash. Jenkins is certain the build is aborted, but the script keeps running. I can kill the script (behind Jenkins) with -9, however.

    I am struggling with this as well! There is documentation which states that Jenkins uses SIGTERM to kill processes, but I too am having a hard time trapping it. One of the problems I have is that even if my script might trap the TERM, Jenkins appears to not wait for termination of the process(es) it has started. It's a bit difficult, then, to know whether the traps work or not when I cannot see the output.

    You should be aware that the bash build scripts are usually invoked with -e, which may "break" your error handling. Jenkins will list all of the processes you have started, including the sleep, and send a TERM to all of them. Your sleep then fails (before you can kill it), causing the rest of the script to fail. It looks like you may have worked around that to get the "Ending" text out, but it caught me and may confuse others trying to reproduce the problem
    The "list all of the processes" part involves an environment variable called BUILD_ID. See https://wiki.jenkins-ci.org/display/JENKINS/ProcessTreeKiller

    By using a set +e (and maybe BUILD_ID=ignore – so many experiments lately) I have managed to make my script ignore TERM, which can consistently lead to an orphaned bash. Jenkins is certain the build is aborted, but the script keeps running. I can kill the script (behind Jenkins) with -9, however.

  5. jenkins-infra-bot commented on Apr 19, 2013

    @jenkins-infra-bot
    Author
    deepchip:
    • Original comment link
    • Raw content of original comment:

      When the shell script starts with the shabang:

      #!/bin/bash
      set -o
      echo $-
      

      I get:

      allexport      	off
      braceexpand    	on
      emacs          	off
      errexit        	off
      errtrace       	off
      functrace      	off
      hashall        	on
      histexpand     	off
      history        	off
      ignoreeof      	off
      interactive-comments	on
      keyword        	off
      monitor        	off
      noclobber      	off
      noexec         	off
      noglob         	off
      nolog          	off
      notify         	off
      nounset        	off
      onecmd         	off
      physical       	off
      pipefail       	off
      posix          	off
      privileged     	off
      verbose        	off
      vi             	off
      xtrace         	off
      hB
      

      When the shell script does not start with the shabang:

      set -o
      echo $-
      

      I get:

      + set -o
      allexport      	off
      braceexpand    	on
      emacs          	off
      errexit        	on
      errtrace       	off
      functrace      	off
      hashall        	on
      histexpand     	off
      history        	off
      ignoreeof      	off
      interactive-comments	on
      keyword        	off
      monitor        	off
      noclobber      	off
      noexec         	off
      noglob         	off
      nolog          	off
      notify         	off
      nounset        	off
      onecmd         	off
      physical       	off
      pipefail       	off
      posix          	on
      privileged     	off
      verbose        	off
      vi             	off
      xtrace         	on
      + echo ehxB
      ehxB
      

      Conclusion: Jenkins forces -ex when there is no shabang (#!/bin/bash) line, so you can control at least that part.

    When the shell script starts with the shabang:

    #!/bin/bash
    set -o
    echo $-
    
    

    I get:

    allexport      	off
    braceexpand    	on
    emacs  	off
    errexit	off
    errtrace       	off
    functrace      	off
    hashall	on
    histexpand     	off
    history	off
    ignoreeof      	off
    interactive-comments	on
    keyword	off
    monitor	off
    noclobber      	off
    noexec 	off
    noglob 	off
    nolog  	off
    notify 	off
    nounset	off
    onecmd 	off
    physical       	off
    pipefail       	off
    posix  	off
    privileged     	off
    verbose	off
    vi     	off
    xtrace 	off
    hB
    
    

    When the shell script does not start with the shabang:

    set -o
    echo $-
    
    

    I get:

    + set -o
    allexport      	off
    braceexpand    	on
    emacs  	off
    errexit	on
    errtrace       	off
    functrace      	off
    hashall	on
    histexpand     	off
    history	off
    ignoreeof      	off
    interactive-comments	on
    keyword	off
    monitor	off
    noclobber      	off
    noexec 	off
    noglob 	off
    nolog  	off
    notify 	off
    nounset	off
    onecmd 	off
    physical       	off
    pipefail       	off
    posix  	on
    privileged     	off
    verbose	off
    vi     	off
    xtrace 	on
    + echo ehxB
    ehxB
    
    

    Conclusion: Jenkins forces -ex when there is no shabang (#!/bin/bash) line, so you can control at least that part.

  6. jenkins-infra-bot commented on May 7, 2013

    @jenkins-infra-bot
    Author
    deepchip:
    • Original comment link
    • Raw content of original comment:

      First point: Changing the value of the BUILD_ID variable to bypass the tree killed is a bad idea: it changes the meaning of BUILD_ID. It would have been better to use a different variable name to express the "don't kill me" idea (hint: if the user sets DONTKILLME=true, then don't kill it).

      Second point: Changing BUILD_ID has no effect on the example script shown in the first comment: it seems Jenkins disables the traps. I tried setting BUILD_ID in a job parameter and in the environment injection plugin to no avail.

      Here are 2 scenarios explaining why Jenkins must not intercept the signals and must let the freestyle jobs handle their own termination: 1) the freestyle job needs a way to remove temporary files it might have created 2) the freestyle job needs a way to kill remote processes it might have created

      I feel scenario 2 needs an explanation: Say the freestyle job spawned a process on a remote host, and disconnected from that remote host. There is no way for the process tree killer to find the connection between the freestyle job bash script, and the remote process, only the freestyle job script can kill the remote job. This is why signals must be propagated and not intercepted.

    First point: Changing the value of the BUILD_ID variable to bypass the tree killed is a bad idea: it changes the meaning of BUILD_ID. It would have been better to use a different variable name to express the "don't kill me" idea (hint: if the user sets DONTKILLME=true, then don't kill it).

    Second point: Changing BUILD_ID has no effect on the example script shown in the first comment: it seems Jenkins disables the traps. I tried setting BUILD_ID in a job parameter and in the environment injection plugin to no avail.

    Here are 2 scenarios explaining why Jenkins must not intercept the signals and must let the freestyle jobs handle their own termination:
    1) the freestyle job needs a way to remove temporary files it might have created
    2) the freestyle job needs a way to kill remote processes it might have created

    I feel scenario 2 needs an explanation: Say the freestyle job spawned a process on a remote host, and disconnected from that remote host. There is no way for the process tree killer to find the connection between the freestyle job bash script, and the remote process, only the freestyle job script can kill the remote job. This is why signals must be propagated and not intercepted.

  7. jenkins-infra-bot commented on May 9, 2013

    @jenkins-infra-bot
    Author
    deepchip:
    • Original comment link
    • Raw content of original comment:

      After experimenting some more, it seems Jenkins cuts the ties to the child process too soon after sending the TERM signal. Some times, when the job runs on the master, I do see the message from the SIGTERM trap, and a lot of times, I don't see it. This makes it hard to tell what really happens. It looks like Jenkins simply needs to wait for the job process to cut the ties to stdout/stderr before it stops listening to the job itself.

      On IRC (May 8, 2013), there was a discussion on changing SIGTERM to SIGTERM -> wait 10 sec -> SIGKILL, but I would prefer if this delay was configurable or even optional, as the clean up done by a properly behaving job could take more than 10 seconds (and it does take a few minutes in my case due to a very large amount of small files to clean up on NFS).

      Here are loosely related but different requests: JENKINS-11995 JENKINS-11996

    After experimenting some more, it seems Jenkins cuts the ties to the child process too soon after sending the TERM signal. Some times, when the job runs on the master, I do see the message from the SIGTERM trap, and a lot of times, I don't see it. This makes it hard to tell what really happens. It looks like Jenkins simply needs to wait for the job process to cut the ties to stdout/stderr before it stops listening to the job itself.

    On IRC (May 8, 2013), there was a discussion on changing SIGTERM to SIGTERM -> wait 10 sec -> SIGKILL, but I would prefer if this delay was configurable or even optional, as the clean up done by a properly behaving job could take more than 10 seconds (and it does take a few minutes in my case due to a very large amount of small files to clean up on NFS).

    Here are loosely related but different requests:
    JENKINS-11995
    JENKINS-11996

  8. jenkins-infra-bot commented on May 10, 2013

    @jenkins-infra-bot
    Author
    owenmehegan:
    • Original comment link
    • Raw content of original comment:

      This may explain a problem I've been seeing. When a user cancels a build while a Ruby 'bundle install' operation is happening, the job exits but the bundle process goes into a zombie-ish state (not literally a zombie process but it never exits), no longer a child of the Jenkins process. I have to kill it manually, and sometimes it freaks out and consumes a lot of resources on the box as well. I'm not sure if we need a bigger/different hammer here, or what.

    This may explain a problem I've been seeing. When a user cancels a build while a Ruby 'bundle install' operation is happening, the job exits but the bundle process goes into a zombie-ish state (not literally a zombie process but it never exits), no longer a child of the Jenkins process. I have to kill it manually, and sometimes it freaks out and consumes a lot of resources on the box as well. I'm not sure if we need a bigger/different hammer here, or what.

  9. jenkins-infra-bot commented on Jul 24, 2013

    @jenkins-infra-bot
    Author
    deepchip:
    • Original comment link
    • Raw content of original comment:

      Jenkins leaks processes when jobs are killed. I think this is related to this issue, so instead of creating a new bug report, I am adding this comment.

      To reproduce the process leak, create a new freestyle job from a fresh install, and enter this script:

      #!/usr/bin/python
      import signal
      import time
      print "Main 1"
      def handler(*ignored):
          print "Ignored 1"
          time.sleep(120)
          print "Ignored 2"
      
      print "Main 2"
      signal.signal(signal.SIGTERM, handler)
      print "Main 3"
      time.sleep(120)
      print "Main 4"
      

      Then execute the build, and after a few seconds once the build is running, hit the red [x] button to kill the job. After the job is killed and Jenkins is done, go to the terminal and look for the python process. You should find something like this:

      $ ps -efH
      ...
      mdanjou   2154  2150  0 08:22 pts/0    00:00:00     bash
      mdanjou   2531  2154 16 08:24 pts/0    00:00:36       java -jar jenkins.war
      mdanjou   2601  2531  0 08:25 pts/0    00:00:00         /usr/bin/python /tmp/hudson3048464595979281901.sh
      

      The python script is still in memory, and still executing. However, Jenkins has cut the ties to the python script.

      Jenkins must not cut the ties until the script is done.

      In this comment, the script is a simple example, in real project scripts, the signal handler is used to clean up temporary files, and to terminate gracefully (e.g. killing other spawned processes).

    Jenkins leaks processes when jobs are killed. I think this is related to this issue, so instead of creating a new bug report, I am adding this comment.

    To reproduce the process leak, create a new freestyle job from a fresh install, and enter this script:

    #!/usr/bin/python
    import signal
    import time
    print "Main 1"
    def handler(*ignored):
        print "Ignored 1"
        time.sleep(120)
        print "Ignored 2"
    
    print "Main 2"
    signal.signal(signal.SIGTERM, handler)
    print "Main 3"
    time.sleep(120)
    print "Main 4"
    
    

    Then execute the build, and after a few seconds once the build is running, hit the red [x] button to kill the job. After the job is killed and Jenkins is done, go to the terminal and look for the python process. You should find something like this:

    $ ps -efH
    ...
    mdanjou   2154  2150  0 08:22 pts/0    00:00:00     bash
    mdanjou   2531  2154 16 08:24 pts/0    00:00:36       java -jar jenkins.war
    mdanjou   2601  2531  0 08:25 pts/0    00:00:00 /usr/bin/python /tmp/hudson3048464595979281901.sh
    
    

    The python script is still in memory, and still executing. However, Jenkins has cut the ties to the python script.

    Jenkins must not cut the ties until the script is done.

    In this comment, the script is a simple example, in real project scripts, the signal handler is used to clean up temporary files, and to terminate gracefully (e.g. killing other spawned processes).

  10. jenkins-infra-bot commented on Jan 16, 2014

    @jenkins-infra-bot
    Author
    matthewlmcclure:
    • Original comment link
    • Raw content of original comment:

      I wrote a script that you can execute periodically from cron to clean up processes orphaned by Jenkins.

    I wrote a script that you can execute periodically from cron to clean up processes orphaned by Jenkins.

  11. jenkins-infra-bot commented on Jun 20, 2014

    @jenkins-infra-bot
    Author
    deepchip:
    • Original comment link
    • Raw content of original comment:

      There is more to it than cleaning up the orphaned processes, which by the way should be done by Jenkins and not as an external process. The way this should work is that Jenkins should send the signal (SIGTERM or SIGTERM) and wait for the sub-processes to do their own cleanup. This gives the sub-processes a chance to propagate the signal to sub-sub-processes of their own (which by the way when you use a grid engine, might be running yet on other remote machines that are not Jenkins slaves).

      I modified the first shell script to write to a file during the traps: Jenkins cuts the ties too early and no files show up anywhere.

      #!/bin/bash
      echo "Starting $0"
      echo "Listing traps"
      trap -p
      echo "Setting trap"
      trap 'echo SIGTERM | tee trap.sigterm; kill $pid; exit 15;' SIGTERM
      trap 'echo SIGINT  | tee trap.sigint; kill $pid; exit 2;' SIGINT
      echo "Listing traps again"
      trap -p
      echo "Sleeping"
      sleep 20 & pid=$!
      echo "Waiting"
      wait $pid
      echo "Exit status: $?"
      echo "Ending"
      

      So the SIGINT -> wait N seconds for the build process to return -> SIGKILL (with a user configurable N) would be an acceptable solution. The value of N should be configurable for each job.

    There is more to it than cleaning up the orphaned processes, which by the way should be done by Jenkins and not as an external process. The way this should work is that Jenkins should send the signal (SIGTERM or SIGTERM) and wait for the sub-processes to do their own cleanup. This gives the sub-processes a chance to propagate the signal to sub-sub-processes of their own (which by the way when you use a grid engine, might be running yet on other remote machines that are not Jenkins slaves).

    I modified the first shell script to write to a file during the traps: Jenkins cuts the ties too early and no files show up anywhere.

    #!/bin/bash
    echo "Starting $0"
    echo "Listing traps"
    trap -p
    echo "Setting trap"
    trap 'echo SIGTERM | tee trap.sigterm; kill $pid; exit 15;' SIGTERM
    trap 'echo SIGINT  | tee trap.sigint; kill $pid; exit 2;' SIGINT
    echo "Listing traps again"
    trap -p
    echo "Sleeping"
    sleep 20 & pid=$!
    echo "Waiting"
    wait $pid
    echo "Exit status: $?"
    echo "Ending"
    
    

    So the SIGINT -> wait N seconds for the build process to return -> SIGKILL (with a user configurable N) would be an acceptable solution. The value of N should be configurable for each job.

  12. jenkins-infra-bot commented on Jul 16, 2014

    @jenkins-infra-bot
    Author
    appid:
    • Original comment link
    • Raw content of original comment:

      I'm also affected by this issue and would highly appreciate the solution proposed by Martin d'Anjou, in which Jenkins waits (a configurable amount of time) for its children to finish.

      Will this be implemented in the near future?

    I'm also affected by this issue and would highly appreciate the solution proposed by Martin d'Anjou, in which Jenkins waits (a configurable amount of time) for its children to finish.

    Will this be implemented in the near future?

  13. jenkins-infra-bot commented on Jul 16, 2014

    @jenkins-infra-bot
    Author
    tintinwebweb:
    • Original comment link
    • Raw content of original comment:

      I see the exact same issue as described in comment-182402.

      I am utilizing the execute python-script build-step to invoke pretty long lasting python processes (parent) that also spawn multiple sub-processes on-demand which are subject to be managed by the parent. I've implemented proper signal handling in order to clean up child processes and threads whenever the parent gets terminated. Unfortunately it looks like - as described in comment-182402 - that jenkins notifies the parent but does not wait for the parent to cleanup and terminate but instead detaches from the process leaving it in an zombie like state. In my case I keep finding processes sitting in futex calls waiting for a lock on a resource that never gets unlocked.

      Clean-up bash scripts are no option as they do not prevent the process from locking, thus some of the external resources that are also locked by my script will never get freed. I see the option to make jenkins wait for the hudson<...>.py process to gracefully terminate and optionally force termination in case the procs cleanup lasts too long.

      I'd appreciate any clues on fixing this issue. Thanks

    I see the exact same issue as described in comment-182402.

    I am utilizing the execute python-script build-step to invoke pretty long lasting python processes (parent) that also spawn multiple sub-processes on-demand which are subject to be managed by the parent. I've implemented proper signal handling in order to clean up child processes and threads whenever the parent gets terminated. Unfortunately it looks like - as described in comment-182402 - that jenkins notifies the parent but does not wait for the parent to cleanup and terminate but instead detaches from the process leaving it in an zombie like state. In my case I keep finding processes sitting in futex calls waiting for a lock on a resource that never gets unlocked.

    Clean-up bash scripts are no option as they do not prevent the process from locking, thus some of the external resources that are also locked by my script will never get freed. I see the option to make jenkins wait for the hudson<...>.py process to gracefully terminate and optionally force termination in case the procs cleanup lasts too long.

    I'd appreciate any clues on fixing this issue.
    Thanks

  14. jenkins-infra-bot commented on Aug 11, 2014

    @jenkins-infra-bot
    Author
    sandor_balazsi:
    • Original comment link
    • Raw content of original comment:

      Is there any progress on this issue?

      We are using jenkins to start a java based test framework. This tool has a couple of java shutdown hook defined that must be executed on the termination of java process.

      Due to this problem jenkins does not wait for the proper termination of our java process.

    Is there any progress on this issue?

    We are using jenkins to start a java based test framework.
    This tool has a couple of java shutdown hook defined that
    must be executed on the termination of java process.

    Due to this problem jenkins does not wait for the proper
    termination of our java process.

  15. jenkins-infra-bot commented on Aug 19, 2014

    @jenkins-infra-bot
    Author
    yevkov:
    • Original comment link
    • Raw content of original comment:

      Hi all,

      I have the same problem, and would appreciate that solution, described by Martin. Is anybody working on implementation?

    Hi all,

    I have the same problem, and would appreciate that solution, described by Martin.
    Is anybody working on implementation?

  16. 41 remaining items

  17. jenkins-infra-bot commented on May 10, 2019

    @jenkins-infra-bot
    Author
    owenmehegan:

    deepchip possibly a question for jthompson.

  18. jenkins-infra-bot commented on Oct 6, 2019

    @jenkins-infra-bot
    Author
    finrodkosh:
    • Original comment link
    • Raw content of original comment:

      I'm using Jenkins 2.198 and JRE  jre-1.8.0-openjdk. I created a free style job based on the script by Oliver Smith. The Build Step defined as:

      sudo su - oracle<<eof
      ./shell_signal_handling
      eof
      

      If i cancel the job the process and it's child process get killed correctly, but the console output is:

      Gestartet durch Benutzer Uwe Teichmann
      Running as SYSTEM
      Baue auf dem Agenten „elendil“ (oracle) in Arbeitsbereich /vorlons/jenkins/elendil/workspace/Training/FreeStyle/Shell_Signal_Handling
      [Shell_Signal_Handling] $ /bin/bash -xe /tmp/jenkins10950746844547967776.sh
      + sudo su - oracle
      Sleeping...
      Build wurde abgebrochen
      Abgebrochen von Uwe Teichmann
      Finished: ABORTED
      

      If i change the Build Step to

      sudo su - oracle<<eof
      ./shell_signal_handling 1>./shell_signal_handling.log 2>&1
      eof
      

      the log file contains

      Sleeping...
      Caught signal, cleaning up...
      

      My conclusion: The behaviour is correct, because:

      • The SIGTERM results in the parent process and his childs to stop and exit correctly.
      • The output of the shell script appears in the console job output as long as the connection is active. When killed, the child processes can't send there output anymore to the parent. To see there output we need the log file.

    I'm using Jenkins 2.198 and JRE  jre-1.8.0-openjdk. I created a free style job based on the script by Oliver Smith. The Build Step defined as:

    sudo su - oracle<
    

    If i cancel the job the process and it's child process get killed correctly, but the console output is:

    Gestartet durch Benutzer Uwe Teichmann
    Running as SYSTEM
    Baue auf dem Agenten „elendil“ (oracle) in Arbeitsbereich /vorlons/jenkins/elendil/workspace/Training/FreeStyle/Shell_Signal_Handling
    [Shell_Signal_Handling] $ /bin/bash -xe /tmp/jenkins10950746844547967776.sh
    + sudo su - oracle
    Sleeping...
    Build wurde abgebrochen
    Abgebrochen von Uwe Teichmann
    Finished: ABORTED
    

    If i change the Build Step to

    sudo su - oracle<./shell_signal_handling.log 2>&1
    eof
    

    the log file contains

    Sleeping...
    Caught signal, cleaning up...
    

    My conclusion: The behaviour is correct, because:

    • The SIGTERM results in the parent process and his childs to stop and exit correctly.
    • The output of the shell script appears in the console job output as long as the connection is active. When killed, the child processes can't send there output anymore to the parent. To see there output we need the log file.
  19. jenkins-infra-bot commented on Oct 6, 2019

    @jenkins-infra-bot
    Author
    deepchip:
    • Original comment link
    • Raw content of original comment:

      finrodkosh are you running the job on the master or on a remote node? The problem manifests itself when the job runs on a remote node.

    finrodkosh are you running the job on the master or on a remote node? The problem manifests itself when the job runs on a remote node.

  20. jenkins-infra-bot commented on Oct 7, 2019

    @jenkins-infra-bot
    Author
    finrodkosh:
    • Original comment link
    • Raw content of original comment:

      The test was done on a local machine, where Jenkins Master and Slave communicate via JNLP.

    The test was done on a local machine, where Jenkins Master and Slave communicate via JNLP.

  21. jenkins-infra-bot commented on Oct 7, 2019

    @jenkins-infra-bot
    Author
    finrodkosh:
    • Original comment link
    • Raw content of original comment:

      At work we use Jenkins 2.138.1. The problem can be reproduced for both freestyle jobs and pipelines. The testcase is performed between two different servers using SLES 12.4, OpenJDP 1.8.0_191-b12.

    At work we use Jenkins 2.138.1. The problem can be reproduced for both freestyle jobs and pipelines. The testcase is performed between two different servers using SLES 12.4, OpenJDP 1.8.0_191-b12.

  22. jenkins-infra-bot commented on Nov 24, 2025

    @jenkins-infra-bot
    Author

    [Original relates_to from Jira: JENKINS-3105]

  23. jenkins-infra-bot commented on Nov 24, 2025

    @jenkins-infra-bot
    Author

    [Original relates_to from Jira: JENKINS-55106]

  24. removed
    bugFor changelog: Minor bug. Will be listed after features
    on Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions