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

Jenkins - Pipeline doesn't allow to execute external batch files with "Start" command in it.

    Details

    • Similar Issues:

      Description

      I am facing issues while executing a batch file from Jenkins pipeline. I think this is a bug in jenkins because I have another job which runs without pipeline using jenkins.

       

      Here is the detailed script and question on [SO|https://stackoverflow.com/questions/49025062/windows-start-command-not-working-from-jenkins-pipeline.]

      *Things I have tried*

      • Failure:

      I have tried executing it from a batch file too using the same configuration. That is also not working.

       

      • Success:
      • However if I run the batch file from command prompt from windows it self, it works fine.
      • Further more I have a job in the same jenkins (without pipeline) which executes the same script externally and that works fine.

       

      Note: I have blueocean plugin installed after ward I setup my entire jenkins.

       

        Attachments

          Activity

          Hide
          oleg_nenashev Oleg Nenashev added a comment -

          Which Pipeline plugin versions do you use?

          Show
          oleg_nenashev Oleg Nenashev added a comment - Which Pipeline plugin versions do you use?
          Hide
          pathfinder2104 Ayushya Devmurari added a comment -

          Oleg Nenashev
          "Pipeline: Multibranch with defaults" plugin version is 1.1.

          Show
          pathfinder2104 Ayushya Devmurari added a comment - Oleg Nenashev "Pipeline: Multibranch with defaults" plugin version is 1.1.
          Hide
          anujgupta Anuj Gupta added a comment -

          I am also facing the same issue. Is any-one able to troubleshoot this problem ? Please assist on this. 

          Show
          anujgupta Anuj Gupta added a comment - I am also facing the same issue. Is any-one able to troubleshoot this problem ? Please assist on this. 
          Hide
          pathfinder2104 Ayushya Devmurari added a comment - - edited

          This is an issue.

          node {
             stage('Preparation') {
                echo 'Pulling code from repo...'
                git branch: 'development', credentialsId: 'CREDENTIAL_ID_GOES_HERE', url: 'GIT_URL'
                echo 'Code fetched.'
             }
             
             stage('Build') {
              //   echo 'Building...'
              //   bat 'npm install'
              //   echo "Killing already running node processes"
              //   bat '''tasklist /fi "imagename eq node.exe" |find ":" > nul
              //   if errorlevel 1 taskkill /f /im "node.exe"'''
              //   bat "npm run prod"
              //  bat 'D:/JenkinsServer/scripts/Demo/Demo.bat'
              //   echo 'Build deployed!'
              bat returnStatus: true, script: 'npm install'
             }
             
             stage('Deployment') {
                 bat '''@echo off
                          echo *************************************
                          echo 	Demo Build Started
                          echo 	@author: Ayushya
                          echo *************************************
                          echo Trying to kill all node processes.
                          taskkill /f /im node.exe
                          echo Running the application...
                          CALL start echo HELLO WORLD....
                          echo Success...'''
             }
             
             stage('Automation Testing'){
                  echo 'Testing...'
                  echo 'Tests passed!'
             }
          }
          
          Show
          pathfinder2104 Ayushya Devmurari added a comment - - edited This is an issue. node { stage('Preparation') { echo 'Pulling code from repo...' git branch: 'development', credentialsId: 'CREDENTIAL_ID_GOES_HERE', url: 'GIT_URL' echo 'Code fetched.' } stage('Build') { // echo 'Building...' // bat 'npm install' // echo "Killing already running node processes" // bat '''tasklist /fi "imagename eq node.exe" |find ":" > nul // if errorlevel 1 taskkill /f /im "node.exe"''' // bat "npm run prod" // bat 'D:/JenkinsServer/scripts/Demo/Demo.bat' // echo 'Build deployed!' bat returnStatus: true, script: 'npm install' } stage('Deployment') { bat '''@echo off echo ************************************* echo Demo Build Started echo @author: Ayushya echo ************************************* echo Trying to kill all node processes. taskkill /f /im node.exe echo Running the application... CALL start echo HELLO WORLD.... echo Success...''' } stage('Automation Testing'){ echo 'Testing...' echo 'Tests passed!' } }
          Hide
          anujgupta Anuj Gupta added a comment -

          Thanks Ayushya for quick reply. I have a master on Linux & slave on Windows and I need to start tomcat using startup.bat on slave machine. The console o/p in Jenkins console o/p shows as success but actually the service won't start on the slave.

           

          node('WS45')
          {
          stage('Start Tomcat'){
          bat '''@echo off
          echo *************************************
          echo Tomcat Started
          echo @author: ANUJ
          echo *************************************
          echo Running the application...
          CALL D:\\******\\Tomcat\\bin
          startup.bat
          echo Success...'''
          }
          }

          Output is :

          [Pipeline] node
          Running on WS45 in C:\Jenkins\workspace\test
          [Pipeline] {
          [Pipeline] stage
          [Pipeline] { (Start Tomcat)
          [Pipeline] bat
          [test] Running batch script
          *************************************
          Tomcat Started
          @author: ANUJ
          *************************************
          Running the application...
          JAVA_OPTS
          Using CATALINA_BASE: "D:******\Tomcat"
          Using CATALINA_HOME: "D:******\Tomcat"
          Using CATALINA_TMPDIR: "D:******\Tomcat\temp"
          Using JRE_HOME: """C:\Program Files\Java\jdk1.8.0_152\jre"""
          Using CLASSPATH: "D:*****\Tomcat\bin\bootstrap.jar;D:******\Tomcat\bin\tomcat-juli.jar"
          Using JAVA_OPTS: "-Xms2048m -Xmx3072m "-Djdk.tls.ephemeralDHKeySize=2048" -Djava.protocol.handler.pkgs=org.apache.catalina.webresources"
          Success...
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          Finished: SUCCESS

          Please advise.

           

           

          Show
          anujgupta Anuj Gupta added a comment - Thanks Ayushya for quick reply. I have a master on Linux & slave on Windows and I need to start tomcat using startup.bat on slave machine. The console o/p in Jenkins console o/p shows as success but actually the service won't start on the slave.   node('WS45') { stage('Start Tomcat'){ bat '''@echo off echo ************************************* echo Tomcat Started echo @author: ANUJ echo ************************************* echo Running the application... CALL D:\\******\\Tomcat\\bin startup.bat echo Success...''' } } Output is : [Pipeline] node Running on WS45 in C:\Jenkins\workspace\test [Pipeline] { [Pipeline] stage [Pipeline] { (Start Tomcat) [Pipeline] bat [test] Running batch script ************************************* Tomcat Started @author: ANUJ ************************************* Running the application... JAVA_OPTS Using CATALINA_BASE: "D:******\Tomcat" Using CATALINA_HOME: "D:******\Tomcat" Using CATALINA_TMPDIR: "D:******\Tomcat\temp" Using JRE_HOME: """C:\Program Files\Java\jdk1.8.0_152\jre""" Using CLASSPATH: "D:***** \Tomcat\bin\bootstrap.jar;D:* *****\Tomcat\bin\tomcat-juli.jar" Using JAVA_OPTS: "-Xms2048m -Xmx3072m "-Djdk.tls.ephemeralDHKeySize=2048" -Djava.protocol.handler.pkgs=org.apache.catalina.webresources" Success... [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline Finished: SUCCESS Please advise.    
          Hide
          pathfinder2104 Ayushya Devmurari added a comment - - edited

          I have also faced similar issue with windows it self, some how the script running from jenkins fails to start the "START" command. From my above posted script I have tried is this "CALL START echo HELLO WORLD...." I am not sure whether it works or not (Mostly didn't and hence this issue) but try it out. We are currently shifted back to the older way of creating free style jobs in jenkins we haven't moved to the pipeline because of this issue. Because we also faced the same. And I think pipeline or free style job does the same thing, their representation of job differs.

          I am sorry I typed it wrong for mistaking this issue with another one, This is still an ISSUE.

          Show
          pathfinder2104 Ayushya Devmurari added a comment - - edited I have also faced similar issue with windows it self, some how the script running from jenkins fails to start the "START" command. From my above posted script I have tried is this "CALL START echo HELLO WORLD...." I am not sure whether it works or not (Mostly didn't and hence this issue) but try it out. We are currently shifted back to the older way of creating free style jobs in jenkins we haven't moved to the pipeline because of this issue. Because we also faced the same. And I think pipeline or free style job does the same thing, their representation of job differs. I am sorry I typed it wrong for mistaking this issue with another one, This is still an ISSUE.
          Hide
          anujgupta Anuj Gupta added a comment -

          Thanks Ayushya for your assistance. 

          Show
          anujgupta Anuj Gupta added a comment - Thanks Ayushya for your assistance. 

            People

            • Assignee:
              Unassigned
              Reporter:
              pathfinder2104 Ayushya Devmurari
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: