- 1 year ago
Jenkins not running sh commands on windows
If you're experiencing issues with Jenkins not executing sh
commands on Windows, it's likely because sh
is specific to Unix-like environments and not recognized by the Windows command prompt. To run commands in Jenkins pipelines on Windows, you need to use the bat
keyword instead.
Here's an example of how to modify a Jenkins pipeline to run commands using the bat
keyword on Windows:
groovypipeline {
agent any
stages {
stage('Build') {
steps {
bat 'echo "Running build on Windows"'
bat 'msbuild MyProject.sln /t:Build'
}
}
stage('Test') {
steps {
bat 'echo "Running tests on Windows"'
bat 'nunit3-console MyTests.dll'
}
}
}
}
In the example above, the bat
keyword is used to execute Windows batch commands within the Jenkins pipeline. Replace the commands inside the bat
statements with your specific build, test, or other commands for your pipeline.
Make sure to save the modified pipeline script and run it in your Jenkins environment. The bat
commands should now be executed correctly on Windows.
Note: If you still need to execute Unix-like commands within a Jenkins pipeline on Windows, you can install and configure a Unix-like shell environment, such as Git Bash or Cygwin, on the Jenkins agent running on Windows. Then, you can use the sh
keyword to execute Unix-like commands.