目前,我们的一个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
答案 0 :(得分: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