【问题标题】:Jenkins - Console output doesn't work properly on WindowsJenkins - 控制台输出在 Windows 上无法正常工作
【发布时间】:2015-06-29 12:43:05
【问题描述】:

我在 main.c 中有一个简单的 hello world 代码。 Jenkins 运行该代码没有问题,但没有将 printf 放入 Jenkins 控制台。

是否有一些配置设置必须更改或我必须安装一些插件才能打印到 Jenkins 控制台?

控制台输出:

Started by user anonymous
Building in workspace C:\Users\ozcanovunc\.jenkins\jobs\jenkins-test\workspace
 > git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git.exe config remote.origin.url https://github.com/ozcanovunc/jenkins-test.git # timeout=10
Fetching upstream changes from https://github.com/ozcanovunc/jenkins-test.git
 > git.exe --version # timeout=10
using .gitcredentials to set credentials
 > git.exe config --local credential.helper store --file=\"C:\WINDOWS\TEMP\git2428021638165579968.credentials\" # timeout=10
 > git.exe -c core.askpass=true fetch --tags --progress https://github.com/ozcanovunc/jenkins-test.git +refs/heads/*:refs/remotes/origin/*
 > git.exe config --local --remove-section credential # timeout=10
 > git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
 > git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision 615e0727146045f351ff36a80b41cd9c16b28aa2 (refs/remotes/origin/master)
 > git.exe config core.sparsecheckout # timeout=10
 > git.exe checkout -f 615e0727146045f351ff36a80b41cd9c16b28aa2
 > git.exe rev-list 615e0727146045f351ff36a80b41cd9c16b28aa2 # timeout=10
[workspace] $ C:\Windows\system32\cmd.exe -xe C:\WINDOWS\TEMP\hudson1467373884410613106.sh
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Users\ozcanovunc\.jenkins\jobs\jenkins-test\workspace>Finished: SUCCESS

提前致谢!

编辑: 我知道有人问过非常相似的question,但似乎没有人对此一无所知。所以我还是想问一下。

编辑: 相同的配置在 Mac OS 上运行正常。

【问题讨论】:

    标签: windows logging jenkins console output


    【解决方案1】:

    Jenkins 是一个构建工具。这意味着它会编译您的代码、构建所有必要的工件、运行测试(如果提供)等。它实际上并不运行您的代码(如果提供了则仅进行单元测试)。

    因此,除非您谈论的是您编写的 Jenkins 插件,否则您将看不到控制台的输出。但是就像您已经提到的那样,您正在编写一个简单的 hello world 应用程序。

    你为什么要从你的代码中打印一些东西到 Jenkins?

    【讨论】:

    • 我实际上并不想打印一些东西。运行一些测试后,我希望生成一些日志文件并将其保存到我的计算机上。
    • 所以您想要一个基于构建期间创建的数据生成日志文件的最终构建步骤?我不确定它到底是什么你想要的,但你可能需要某种 Jenkins 插件并在构建过程结束时触发它。看起来您的问题与您最初提出的问题不同。
    • 不,不完全是。我要做的就是运行一个可执行文件并将其输出重定向到某个文件。在这种情况下 ./main >> log.txt。但为了实现这一点,我需要确保是否能够将某些内容打印到 Jenkins 控制台。
    • 我仍然不明白为什么你只是不将你想要的东西从你的代码中写入日志文件。我不明白为什么你需要能够为此打印一些东西到 Jenkins 的输出中。无论如何,我只知道如何在 Java 中将输出写入 Jenkins 控制台:使用 TaskListener 类的 getLogger。但我想它不会真正帮助你。也许你可以找到一个替代品。
    • 正如我所说,我打算将我的代码输出重定向到一个日志文件,该文件将存储在我的硬盘上。我不知道是否有其他方法可以实现这一目标。我应该如何使用 TaskListener 类?我要把那个代码放在哪里?
    【解决方案2】:
    [workspace] $ C:\Windows\system32\cmd.exe -xe C:\WINDOWS\TEMP\hudson1467373884410613106.sh
    Microsoft Windows [Version 6.3.9600]
    (c) 2013 Microsoft Corporation. All rights reserved.
    
    C:\Users\ozcanovunc\.jenkins\jobs\jenkins-test\workspace>Finished: SUCCESS
    

    这表明您的 Jenkins 作业正在尝试使用 cmd.exe 在 Windows 上执行 Shell 脚本块,这不会执行 shell 脚本的内容。您必须在 Windows 代理上安装 Shell 脚本运行时(即 Bash)(并将 Jenkins 配置为使用 sh.exe 或将其保留为默认值以在 PATH 中使用 sh)或将您的作业转换为使用批处理脚本块。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-04
      相关资源
      最近更新 更多