【问题标题】:Jenkins dotnet test詹金斯网络测试
【发布时间】:2022-12-16 08:19:25
【问题描述】:

如果单元测试失败,管道结束。无论失败还是成功,我都想发送单元测试结果。我正在使用“Execute Shell”构建触发器。 (并且想要)

/dotnet/dotnet test --no-build --logger "trx;LogFileName=UnitTests.xml" /pathtotest

curl -X POST -H "Content-Type:application/xml" -d @/var/jenkins_home/workspace/MyJob/UnitTests.xml https://myendpoint.com

如果单元测试失败,curl 命令将不会运行,因为管道以失败告终。如果单元测试成功,curl 命令将运行。它无论如何都希望它运行。

我怎么做?

【问题讨论】:

  • 添加一个post action 并在总是健康)状况?
  • 默认情况下,Jenkins 没有在后期操作中执行其他 shell 命令的选项。 (我使用的是 execute shell,而不是 groovy 管道)我确实找到了一个插件,它允许您在管道后操作中执行其他命令,并且有效。谢谢!我仍然很好奇是否可以在没有插件的情况下完成同样的工作——几乎就像一个 try catch linux cmd?不知道有没有这种东西。

标签: .net jenkins curl


【解决方案1】:

我们使用“.Net SDK Support”插件。它比编写必须在 windows 和 linux 节点上运行的 shell 脚本要干净得多。

使用它,您只需设置continueOnError:trueunstableIfErrors:true。这允许构建继续,但在测试失败时将其标记为“黄色”(不稳定)而不是红色。

例子:

 echo("Running tests in '${buildSolutionFile}' calling 'dotnet test' ...")
 dotnetTest( configuration: my_configuration_map, noBuild: true, project: buildSolutionFile, continueOnError: true, unstableIfErrors: true, properties:[:], logger:"trx;LogFileName=tests-results-${appName}.trx", filter: dotnetTestFilter, sdk: sdkVersion)

这是参考文档:https://www.jenkins.io/doc/pipeline/steps/dotnet-sdk/#dotnettest-net-run-unit-tests-test

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多