我可以在Jenkins仪表板中使跳过的测试更加突出吗?

时间:2013-03-18 17:13:58

标签: junit jenkins

我在Jenkins有一个正在测试的项目(“测试安装”;它做了一些回归测试,验证安装程序是否正常工作)。这个项目对Jenkins控件之外的东西有一个软依赖:如果最新的安装程序不可用,那么我们就无法测试它。我们总是可以重新测试一个旧的安装程序,这看起来值得做(我们有CPU周期,所以我们也可以烧掉它们。)

如果安装程序不是最新版本,我想要的是发出响亮的警告,然后继续进行测试。

我尝试的第一件事是在安装程序过期时进行测试失败。这很突出,但令人困惑,因为安装测试实际上并不是失败的东西。

现在我有相同的测试,但它使用JUnit假设而不是断言,这意味着测试跳过或通过。这也不太完美,因为Jenkins在首页上报告了“9次测试,0次失败”,只有当我在测试结果中向下钻取多个层时,我才会看到9次测试中有1次被跳过。 / p>

我可以让Jenkins在头版报告跳过的测试吗?我找不到合适的插件。是否有更好的方法来警告安装程序过时?

1 个答案:

答案 0 :(得分:1)

为您回答问题有点晚了,但可能会对其他人有所帮助。 。 。

在这样的情况下,我认为最简单的两件事很有效:

  • 添加一项额外的测试,以检查最新的安装程序版本并失败。这样该工作将被标记为不稳定。

  • 或者您可以使用构建后插件之一来检查日志并将作业标记为失败而不是不稳定。

没有一种简单方法可以使跳过的测试更加突出。

但是您可以对测试结果进行一些后处理。

我们在作业脚本/测试脚本中生成VERSION.txt文件,并将其放在作业工作区中。然后,我们使用Groovy Postbuild操作并设置作业描述:

“ Groovy postbuild”

def currentBuild = Thread.currentThread().executable
def ws = manager.build.workspace.getRemote()
String desc = new File(ws + "/VERSION.txt").text
currentBuild.setDescription(desc)

这非常有用,我们可以在作业历史记录中查看测试的版本或其他详细信息。

更突出地标记事物。 。 。 >;),您可以使用徽章和一些常规样式。 build badge example, view in job history side-bar. badges also show in job page, in build monitor views, . . .

使用的插件:

https://wiki.jenkins.io/display/JENKINS/Groovy+Postbuild+Plugin

Groovy Postbuild插件是唯一真正需要的插件。 徽章API是Groovy Postbuild插件的一部分。

https://wiki.jenkins.io/display/JENKINS/Groovy+plugin

Groovy插件可用于尝试groovy或使用groovy进行作业。

https://wiki.jenkins.io/display/JENKINS/Build+Trigger+Badge+Plugin

实际上,可以在jenkins groovy postbuild插件中使用徽章。如果使用了多种触发器,但设置徽章实际上并不需要,我使用的BuildTriggerBadge插件很有用。我将其包含在此处,因为它已安装,但我不是100%确定没有它就可以运行我的代码(但我可以保证98.5%)。我没有安装徽章插件。

请参阅以下有关徽章的常规实验:

def currentBuild = Thread.currentThread().executable
def ws = manager.build.workspace.getRemote()
String desc = new File(ws + "/VERSION.txt").text
currentBuild.setDescription(desc)

if (desc.contains("ERROR")) {
  coverageText="VarkeninK, SomethinK iz bad."
  // Apologies :-7 I can only assume this was from Viktor in http://www.userfriendly.org/ web comic
  manager.addShortText(coverageText, "black", "repeating-linear-gradient(45deg, 
yellow, yellow 10px, Orange 10px, Orange 20px)", "0px", "white")
}

manager.addShortText("GreyWhite0pxWhite", "grey", "white", "0px", "white")
manager.addShortText("BlackGreen0pxWhite", "black", "green", "0px", "white")
manager.addShortText("BlackGreen5pxWhite", "black", "green", "5px", "white")
manager.addShortText("VERSION WhiteGreen0pxWhite", "white", "green", "0px", "white")
manager.addShortText("WhiteGreen5pxWhite", "white", "green", "5px", "white")

manager.addShortText("VERSION Black on Lime Green", "black", "limegreen", "0px", "white")

// darkgrey is lighter than grey!! :-P
manager.addShortText("OBSOLETE YellowDarkGrey5pxGrey", "yellow", "darkgrey", "5px", "grey")
manager.addShortText("OBSOLETE YellowGrey5pxGrey", "yellow", "grey", "5px", "grey")


manager.removeBadges()


manager.addShortText("VERSION Black on Lime Green", "black", "limegreen", "0px", "white")
manager.addShortText(desc, "black", "limegreen", "5px", "white")
manager.addShortText("OBSOLETE YellowGrey5pxGrey", "yellow", "grey", "5px", "grey")

manager.addBadge("warning.gif", "Warning test")
manager.addWarningBadge("other warning test")


// https://wiki.jenkins.io/display/JENKINS/Groovy+Postbuild+Plugin

// contains(file, regexp) - returns true if the given file contains a line matching regexp.
// logContains(regexp) - returns true if the build log file contains a line matching regexp.
// getMatcher(file, regexp) - returns a java.util.regex.Matcher for the first occurrence of regexp in the given file.
// getLogMatcher(regexp) - returns a java.util.regex.Matcher for the first occurrence of regexp in the build log file.
// setBuildNumber(number) - sets the build with the given number as current build. The current build is the target of all methods that add or remove badges and summaries or change the build result.
// addShortText(text) - puts a badge with a short text, using the default format.
// addShortText(text, color, background, border, borderColor) - puts a badge with a short text, using the specified format.
// addBadge(icon, text) - puts a badge with the given icon and text. In addition to the 16x16 icons offered by Jenkins, groovy-postbuild provides the following icons:
//  - completed.gif
//  - db_in.gif
//  - db_out.gif
//  - delete.gif
//  - error.gif
//  - folder.gif
//  - green.gif
//  - info.gif
//  - red.gif
//  - save.gif
//  - success.gif
//  - text.gif
//  - warning.gif
//  - yellow.gif
// addBadge(icon, text, link) - like addBadge(icon, text), but the Badge icon then actually links to the given link (since 1.8)
// addInfoBadge(text) - puts a badge with  info icon and the given text.
// addWarningBadge(text) - puts a badge with  warning icon and the given text.
// addErrorBadge(text) - puts a badge with  error icon and the given text.
// removeBadges() - removes all badges from the current build.
// removeBadge(index) - removes the badge with the given index.
// createSummary(icon) - creates an entry in the build summary page and returns a summary object corresponding to this entry. The icon must be one of the 48x48 icons offered by Jenkins. You can append text to the summary object by calling its appendText methods:
// appendText(text, escapeHtml)
// appendText(text, escapeHtml, bold, italic, color)
// removeSummaries() - removes all summaries from the current build.
// removeSummary(index) - removes the summary with the given index.
// buildUnstable() - sets the build result to UNSTABLE.
// buildFailure() - sets the build result to FAILURE.
// buildSuccess() - sets the build result to SUCCESS.