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

dos "exit" command not functioning correctly

    XMLWordPrintable

Details

    Description

      if you attempt to run a dos batch file that has an "exit" command within it then the task does not notice that the interpreter has terminated.

      e.g. in workflow create a CPS with the following

      node {
            bat '''echo hello
      exit 1'''
            echo 'should not be seen'
      }
      

      This results in a workflow that will run forever.

      Attachments

        Issue Links

          Activity

            danielbeck Daniel Beck added a comment -

            Isn't that what the /b flag is for?

            danielbeck Daniel Beck added a comment - Isn't that what the /b flag is for?
            teilo James Nord added a comment -

            well that depends on your perspective.

            There is no other cmd.exe interpreter in the view of the user - so they would logically assume that the script is run with cmd.exe /k the_contents_of_the_stuff.

            regardless of that, the end result is not good - having a task running that has died looks bad for Jenkins and gives the impression of a Jenkins issue even if it is PEBKAC.

            teilo James Nord added a comment - well that depends on your perspective. There is no other cmd.exe interpreter in the view of the user - so they would logically assume that the script is run with cmd.exe /k the_contents_of_the_stuff. regardless of that, the end result is not good - having a task running that has died looks bad for Jenkins and gives the impression of a Jenkins issue even if it is PEBKAC.
            jglick Jesse Glick added a comment -

            Since I have no idea what /b or /k do I am passing back to you!

            jglick Jesse Glick added a comment - Since I have no idea what /b or /k do I am passing back to you!
            teilo James Nord added a comment -
            cmd.exe /?
                Starts a new instance of the Windows command interpreter
                /K      Carries out the command specified by string but remains
            
            > help exit
            Quits the CMD.EXE program (command interpreter) or the current batch
            script.
            
            EXIT [/B] [exitCode]
              /B          specifies to exit the current batch script instead of
                          CMD.EXE.  If executed from outside a batch script, it
                          will quit CMD.EXE
            

            basically if you forget to add /b to your dos script (e.g. if you want to terminate early using exit) you will kill the cmd.exe process and Jenkins will sit until the end of days and not realize...

            teilo James Nord added a comment - cmd.exe /? Starts a new instance of the Windows command interpreter /K Carries out the command specified by string but remains > help exit Quits the CMD.EXE program (command interpreter) or the current batch script. EXIT [/B] [exitCode] /B specifies to exit the current batch script instead of CMD.EXE. If executed from outside a batch script, it will quit CMD.EXE basically if you forget to add /b to your dos script (e.g. if you want to terminate early using exit) you will kill the cmd.exe process and Jenkins will sit until the end of days and not realize...
            jglick Jesse Glick added a comment -

            Using /k rather than /c to run the wrapper script does not seem to have any effect. Easily seen outside Jenkins:

            C:\Documents and Settings\Jesse Glick\JENKINS-27419>type main.bat wrap.bat
            
            main.bat
            
            
            echo hello world
            exit 1
            
            wrap.bat
            
            
            call "main.bat" > "log.txt" 2>&1
            echo %ERRORLEVEL% > "result.txt"
            
            C:\Documents and Settings\Jesse Glick\JENKINS-27419>cmd /k wrap.bat
            
            C:\Documents and Settings\Jesse Glick\JENKINS-27419>call "main.bat"  1>"log.txt" 2>&1
            
            C:\Documents and Settings\Jesse Glick\JENKINS-27419>type log.txt
            
            C:\Documents and Settings\Jesse Glick\JENKINS-27419>echo hello world
            hello world
            
            C:\Documents and Settings\Jesse Glick\JENKINS-27419>exit 1
            
            C:\Documents and Settings\Jesse Glick\JENKINS-27419>type result.txt
            The system cannot find the file specified.
            
            C:\Documents and Settings\Jesse Glick\JENKINS-27419>
            

            If you use exit /b 1 in main.bat then it works (with /c or /k).

            Any other ideas?

            jglick Jesse Glick added a comment - Using /k rather than /c to run the wrapper script does not seem to have any effect. Easily seen outside Jenkins: C:\Documents and Settings\Jesse Glick\JENKINS-27419>type main.bat wrap.bat main.bat echo hello world exit 1 wrap.bat call "main.bat" > "log.txt" 2>&1 echo %ERRORLEVEL% > "result.txt" C:\Documents and Settings\Jesse Glick\JENKINS-27419>cmd /k wrap.bat C:\Documents and Settings\Jesse Glick\JENKINS-27419>call "main.bat" 1>"log.txt" 2>&1 C:\Documents and Settings\Jesse Glick\JENKINS-27419>type log.txt C:\Documents and Settings\Jesse Glick\JENKINS-27419>echo hello world hello world C:\Documents and Settings\Jesse Glick\JENKINS-27419>exit 1 C:\Documents and Settings\Jesse Glick\JENKINS-27419>type result.txt The system cannot find the file specified. C:\Documents and Settings\Jesse Glick\JENKINS-27419> If you use exit /b 1 in main.bat then it works (with /c or /k ). Any other ideas?
            jglick Jesse Glick added a comment -

            I think I got it: use cmd rather than call in the wrapper script.

            jglick Jesse Glick added a comment - I think I got it: use cmd rather than call in the wrapper script.

            Code changed in jenkins
            User: Jesse Glick
            Path:
            src/main/java/org/jenkinsci/plugins/durabletask/WindowsBatchScript.java
            src/test/java/org/jenkinsci/plugins/durabletask/WindowsBatchScriptTest.java
            http://jenkins-ci.org/commit/durable-task-plugin/c0edb1d21c9963f4fe865dc024536972381d5d32
            Log:
            [FIXED JENKINS-27419] Properly handle scripts that call exit without /b.

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: src/main/java/org/jenkinsci/plugins/durabletask/WindowsBatchScript.java src/test/java/org/jenkinsci/plugins/durabletask/WindowsBatchScriptTest.java http://jenkins-ci.org/commit/durable-task-plugin/c0edb1d21c9963f4fe865dc024536972381d5d32 Log: [FIXED JENKINS-27419] Properly handle scripts that call exit without /b.

            Code changed in jenkins
            User: Jesse Glick
            Path:
            src/main/java/org/jenkinsci/plugins/durabletask/WindowsBatchScript.java
            src/test/java/org/jenkinsci/plugins/durabletask/WindowsBatchScriptTest.java
            http://jenkins-ci.org/commit/durable-task-plugin/807eca36b3ca37d00518e957940117dd1ea3df54
            Log:
            Merge pull request #12 from jglick/exitCommand-JENKINS-27419

            JENKINS-27419 Properly handle scripts that call exit without /b

            Compare: https://github.com/jenkinsci/durable-task-plugin/compare/d652a99ee282...807eca36b3ca

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: src/main/java/org/jenkinsci/plugins/durabletask/WindowsBatchScript.java src/test/java/org/jenkinsci/plugins/durabletask/WindowsBatchScriptTest.java http://jenkins-ci.org/commit/durable-task-plugin/807eca36b3ca37d00518e957940117dd1ea3df54 Log: Merge pull request #12 from jglick/exitCommand- JENKINS-27419 JENKINS-27419 Properly handle scripts that call exit without /b Compare: https://github.com/jenkinsci/durable-task-plugin/compare/d652a99ee282...807eca36b3ca

            I've just experienced the same issue even while using the /b key and doing promotion.
            So in build promotion windows script if you do exit /b 255 it will result Pending promotion status to remain forever

            arturkor Artur Korobeynyk added a comment - I've just experienced the same issue even while using the /b key and doing promotion. So in build promotion windows script if you do exit /b 255 it will result Pending promotion status to remain forever
            danielbeck Daniel Beck added a comment -

            arturkor This issue is about the Durable Task Plugin, not the Promoted Builds Plugin.

            danielbeck Daniel Beck added a comment - arturkor This issue is about the Durable Task Plugin, not the Promoted Builds Plugin.

            People

              jglick Jesse Glick
              teilo James Nord
              Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: