问题
Stage("execution") {
Steps {
bat 'start cmd.exe /c c:\\users\\doc\\sample.bat'
}
}
The above script is just opening the cmd
prompt and executing it. It's not taking the output of the execution. Even if the execution fails, the stage is shown as successful and it moves to the next stage for deployment. I want to develop it so that the output in the cmd
prompt should be taken as input by Jenkins and stage should go on. If the stage fails during execution, the stage should show failure and if the execution succeeds, the stage should show success in Jenkins. Can anyone help?
Another question: If the batch file is located in Git, how to give the path in the above script?
回答1:
Using the start
command, you are creating a new detached console process which Jenkins cannot keep track of.
Do it like this instead:
bat 'call "c:\\users\\doc\\sample.bat"'
This runs the batch file in the same environment as the current script and waits for the batch file to end. Jenkins will be able to capture the standard output and detect errors through the exit code of the batch file.
You may write @call
to hide the command-line from the output.
来源:https://stackoverflow.com/questions/61287022/how-to-direct-the-cmd-line-output-to-jenkins