How to Direct the Cmd line output to jenkins

风流意气都作罢 提交于 2021-02-05 07:41:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!