- 1 year ago
Jenkins as Windows Service - Running Windows batch command <some program> is not recognized
When running Jenkins as a Windows service, it runs under a different user context and environment variables than when running Jenkins interactively. This can sometimes cause issues with recognizing certain programs or commands in your batch scripts.
To resolve the "is not recognized" error, you have a few options:
Use the full path to the program: Instead of relying on the system's PATH variable to locate the program, provide the full path to the program in your batch script. For example:
vbnetC:\path\to\program.exe <arguments>
Set the PATH environment variable: Configure the PATH environment variable within your Jenkins job or pipeline to include the directory where the program is located. You can do this using the
bat
step in Jenkins pipeline or using thesetx
command in a Windows batch script. For example:arduinobat 'set PATH=%PATH%;C:\path\to\program'
Specify the working directory: If the program relies on specific files or dependencies located in a specific directory, make sure to set the working directory for the batch script in your Jenkins job or pipeline to the appropriate directory using the
dir
step in Jenkins pipeline or thecd
command in a Windows batch script. For example:javascriptdir('C:\path\to\working\directory') {
bat 'program.exe <arguments>'
}
By using one of these approaches, you should be able to ensure that the program or command is recognized and executed correctly within your Jenkins job or pipeline running as a Windows service.