Jenkins job not seeing console output

2019-06-06 22:23发布

First, I'm not the admin, so there might be something config-wise that's not correct, leading to this issue. I can configure the one job I have access to configure and that is all.

I am performing a Windows build, using a combination of shell scripts (using git-bash.exe) and Windows batch file. The sole jenkins build script is a shell script containing only:

#!c:\Program Files\Git\git-bash.exe
$WORKSPACE/builds/step1.sh |& tee $WORKSPACE/build_output.log

(My git-bash.exe version is '4.3.42(5)-release' and the |& shorthand appears to be working as well as 2>&1 | did.)

That script (step1.sh) does some prep work and then kicks off the build process by calling batch files and shell scripts in sequence.

The build works and I am rewarded with a nice MSI file. The build_output.log file contains a full log of the entire build process as was also displayed in the console on the slave.

The problem is, jenkins fails to capture that console output (ie, the contents of build_output.log). All I see for console output is:

Started by user Jon
[EnvInject] - Loading node environment variables.
Building remotely on Win2k12r2_x64-build (Build VM (xx.xx.xx.xx) Windows Client) in workspace /f/git/project
[project] $ c:\Program Files\Git\git-bash.exe C:\Users\ADMINI~1\AppData\Local\Temp\1\hudson386179994146389782.sh
Notifying upstream projects of job completion
Finished: SUCCESS

What do I need to do to capture the build log in jenkins? I specifically don't want to put my step1.sh script into jenkins since I want to be able to exactly reproduce what the build team (who manage the jenkins server) see when a build fails. We want the build scripts under source control, available to all and runnable by all (in their own sandbox). I did try simply cat-ing the build log from the jenkins two-line shell script to see if that captured it... it did not.

1条回答
放我归山
2楼-- · 2019-06-06 22:55

I've used a similar command in Jenkins to tee a log:

./foo.sh 2>&1 | tee output.txt

(The version of git-bash.exe on the Jenkins server I was using did not support |&, so I had to use the long form to redirect stderr.)

In your case, if neither the console log or build_output.log contain any text, I'm guessing it's one of the following:

  1. step1.sh is not actually outputting anything

    Troubleshoot: Run that script in Jenkins without any redirection or tee, and verify it prints something to the console. Don't rely only on a local run in case something in your Jenkins environment (such as a Jenkins plugin) is causing the problem.

  2. |& is silently failing

    Troubleshoot: Configure your job to run echo foo>&2 |& cat, and verify you see "foo" in your console. If that fails, try the long form: echo foo>&2 2>&1 | cat.

  3. tee is silently failing

    Troubleshoot: Configure your job to run echo foo>&2 |& tee out.txt, and verify you see "foo" in both your console and out.txt. If that fails, try the long form: echo foo>&2 2>&1 | tee out.txt.

查看更多
登录 后发表回答