anand chinnu
anand chinnu

Reputation: 21

How to Direct the Cmd line output to jenkins

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?

Upvotes: 2

Views: 2458

Answers (1)

zett42
zett42

Reputation: 27796

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.

Upvotes: 1

Related Questions