开发者

Getting a shell error code from curl in Jenkins while still displaying output in console

I am using a shell script in Jenkins that, at a certain point, uploads a file to a server using curl. I would like to see whatever output curl produces but also check whether it 开发者_如何学Cis the output I expect. If it isn't, then I want to set the shell error code to > 0 so that Jenkins knows the script failed.

I first tried using curl -f, but this causes the pipe to be cut as soon as the upload fails and the error output never gets to the client. Then I tried something like this:

curl ...params... | tee /dev/tty | \
  xargs -I{} test "Expected output string" = '{}'

This works from a normal SSH shell but in the Jenkins console output I see:

tee: /dev/tty: No such device or address

I'm not sure why this is since I thought Jenkins was communicating with the slave using a normal SSH shell. In any case, the whole xargs + test thing strikes me as a bit of a hack.

Is there a way to accomplish this in Jenkins so that I can see the output and also test whether it matches a specific string?


When Jenkins communicates with slave via SSH, there is no terminal allocated, and so there is no /dev/tty device for that process.

Maybe you can send it to /dev/stderr instead? It will be a terminal in an interactive session and some log file in non-interactive session.


Have you thought about using the Publish over SSH Plugin instead of using curl? Might save you some headache.

If you just copy the file from master to slave there is also a plugin for that, copy to slave Plugin.

Cannot write any comments yet, so I had to post it as an answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜