Execute WIndows bat file in Jenkins

I am using Jenkins 2.46.1 I have a build build plugin installed and I want to execute a windows batch file in it. The batch file should be executed in a new command window and not in the jenkins console output. I am giving Jenkins' bottom pipeline groovy script:

node {  
    stage 'Init'
    bat '''
        call C:\\myprj\\mybat.bat stop
        EXIT /B 0
    '''
    stage 'Deploy'
    bat '''call C:\\myprj\\mybat.bat'''
}

      

At the init stage I want to kill the process if it is already open, and at the deploy stage it should open a new command window and run my batch file. The problem is the above doesn't work. The line completed successfully, but no command prompt window opens. Pls suggest

+3


source to share


1 answer


Technically, in order to do what you ask, you must be able to run

bat 'start cmd.exe /c C:\\myprj\\mybat.bat'

      



This will launch new command windows (cmd.exe) and run the specified batch file. You won't see anything depending on how your Jenkins slave is running. (for example, if it's running as a windows service or another user, you won't see anything)

+3


source







All Articles