1

目前我们的一个 Jenkins 构建失败了。我希望它在构建失败时通过(或显示绿色)。同样,当案例通过时,我希望我们的构建失败(或显示红色)。我正在配置的构建是我们的“已知问题构建”。所以只有失败的案例才会进入那里。这个构建的目标是让它在失败时通过,因为我们知道它已经坏了。当我们的开发人员修复它时,构建应该会失败(这意味着现在有些东西正在工作),以便我们可以将它从构建中移出到我们的核心构建中。我阅读了一篇关于 --wip 开关的文章,并已成功将其配置到我们的构建中。我一直收到电子邮件说 Jenkins 构建已恢复正常,对我来说这似乎有效。但是,当您查看构建本身时,它看起来好像失败了。该构建被标记为红色,这意味着它失败了,并且测试说它们失败了。他们通过的唯一指标是我收到的电子邮件。但这不是我想要的预期行为。该构建似乎提醒我它通过了,但看起来好像失败了。有没有办法让红色按钮变成绿色,所以当我们查看我们的构建时,我们知道什么时候出了问题。

现在我添加|| exit 1到我的命令的末尾,它应该反转失败和通过的标志。我还创建了一个简短的 bash 脚本来反转按钮颜色,这也不起作用。我相信我错过了一些东西。有任何想法吗?下面列出的是我正在运行以启动我们的构建的命令:

cucumber --wip --profile wip --format json -o cucumber.json /var/lib/jenkins/workspace/Cucumber\ -\ Known\ Issues\ Build/ SITE=devel || exit 1
4

1 回答 1

2

command || exit 1意思是“如果command失败,那么exit 1(即失败)

您刚刚说过,如果您的命令成功,您希望构建失败,因此您需要:
command && exit 1 || exit 0

如上,如果command成功,则构建失败,否则(如果command不成功),则构建成功

这是作业的控制台输出:

Started by upstream project "Cucumber - Devel Parent Build" build number 58
originally caused by: 
Started by timer
Xvfb starting$ /usr/bin/Xvfb :75 -screen 0 1024x768x24 -fbdir /var/lib/jenkins/2013-01-25_22-24-203386303931627225842xvfb
Building remotely on dev548 in workspace /var/lib/jenkins/workspace/Cucumber - Known Issues Build
Checkout:Cucumber - Known Issues Build / /var/lib/jenkins/workspace/Cucumber - Known Issues Build - hudson.remoting.Channel@322535f5:dev548
Using strategy: Default
Last Built Revision: Revision f48428cc3128a0d6369ea99bbdbdf419bc29b173 (Cucumber/master)
Fetching changes from 1 remote Git repository
Fetching upstream changes from git@testdrivesite.beanstalkapp.com:/cucumber.git
Commencing build of Revision dad2f8792ec364e79dd76840f787d5e72676b03f (Cucumber/master)
Checking out Revision dad2f8792ec364e79dd76840f787d5e72676b03f (Cucumber/master)
Deleting old artifacts from #137
[Cucumber - Known Issues Build] $ /bin/bash /tmp/hudson3196742906607332265.sh
Using the wip profile...
Xvfb stopping
Archiving artifacts
[CucumberReportPublisher] Compiling Cucumber Html Reports ...
[CucumberReportPublisher] detected this build is running on a slave 
[CucumberReportPublisher] copying json from: file:/var/lib/jenkins/workspace/Cucumber%20-%20Known%20Issues%20Build/to reports directory: file:/var/lib/jenkins/jobs/Cucumber%20-%20Known%20Issues%20Build/builds/2013-01-25_22-24-20/cucumber-html-reports/
[CucumberReportPublisher] Generating HTML reports
Build step 'Publish cucumber results as a report' marked build as failure
Notifying upstream projects of job completion
Finished: FAILURE

这是我的配置中的构建步骤:

#!/bin/bash
source /usr/local/rvm/environments/default
/usr/local/rvm/gems/ruby-1.9.2-p320/bin/cucumber --profile wip --format json -o cucumber.json /var/lib/jenkins/workspace/Cucumber\ -\ Known\ Issues\ Build/ SITE=devel && exit 1 || exit 0
于 2013-01-24T18:37:25.097 回答