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.

      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.

       

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

          Oleg Nenashev added a comment -

          Which Pipeline plugin versions do you use?

          Oleg Nenashev added a comment - Which Pipeline plugin versions do you use?

          oleg_nenashev
          "Pipeline: Multibranch with defaults" plugin version is 1.1.

          Ayushya Devmurari added a comment - oleg_nenashev "Pipeline: Multibranch with defaults" plugin version is 1.1.

          Anuj Gupta added a comment -

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

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

          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!'
             }
          }
          

          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!' } }

          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.

           

           

          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.    

          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.

          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.

          Anuj Gupta added a comment -

          Thanks Ayushya for your assistance. 

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

          any word on when this issue would be fixed?

          Auden RovelleQuartz added a comment - any word on when this issue would be fixed?

          HI Team,

          I have batch execution with jenkin job works fine. But in pipelien it is not getting executed. Looks even bat is not executed and no error reported. Even when batch file not exists, also it is getting passed. Any idea why?

           

          pipeline {
          agent any

          stages {
          stage('Hello') {
          steps {
          echo 'Hello'
          //bat "C:\\JenKin_Jobs
          NetUSeIDrive.bat"
          //bat returnStatus: true, script: 'C:/JenKin_Jobs/NetUSeIDrive.bat'
          bat "${WORKSPACE}/NetUSeIDrive.bat"
          }
          }
          }
          }

          commented are the options tried with no luck

          Selvaganapathy D added a comment - HI Team, I have batch execution with jenkin job works fine. But in pipelien it is not getting executed. Looks even bat is not executed and no error reported. Even when batch file not exists, also it is getting passed. Any idea why?   pipeline { agent any stages { stage('Hello') { steps { echo 'Hello' //bat "C:\\JenKin_Jobs NetUSeIDrive.bat" //bat returnStatus: true, script: 'C:/JenKin_Jobs/NetUSeIDrive.bat' bat "${WORKSPACE}/NetUSeIDrive.bat" } } } } — commented are the options tried with no luck

            Unassigned Unassigned
            pathfinder2104 Ayushya Devmurari
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: