Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让Jenkins build monitor插件显示徽章?_Jenkins_Jenkins Pipeline_Jenkins Plugins_Badge - Fatal编程技术网

如何让Jenkins build monitor插件显示徽章?

如何让Jenkins build monitor插件显示徽章?,jenkins,jenkins-pipeline,jenkins-plugins,badge,Jenkins,Jenkins Pipeline,Jenkins Plugins,Badge,我正在尝试将badges插件与jenkins build monitor插件集成,根据最新的发行说明,现在应该可以实现。() 我已经下载并安装了所有必需的插件和依赖项。 并在Post always块中将以下代码添加到我的Jenkins管道中 addBadge(icon:"text.gif", text:"cucumber-report", id:"cukerep", link:"http://www.google.com") 但是在构建完成且没有错误后,我的构建监视器插件视图中不会显示任何徽章

我正在尝试将badges插件与jenkins build monitor插件集成,根据最新的发行说明,现在应该可以实现。()

我已经下载并安装了所有必需的插件和依赖项。 并在Post always块中将以下代码添加到我的Jenkins管道中

addBadge(icon:"text.gif", text:"cucumber-report", id:"cukerep", link:"http://www.google.com")
但是在构建完成且没有错误后,我的构建监视器插件视图中不会显示任何徽章

我还勾选了build monitor视图中的show badges框


有人知道我遗漏了什么吗?

我没有使用jenkins管道,而是使用带有groovy postbuild插件徽章的构建监视器插件。在插件中勾选show badges框后,我可以在build monitor显示屏中看到这些徽章

作为一个完整的猜测,manager.addBadge会在管道代码中工作吗

我建议安装Groovy PostBuild插件并尝试类似的方法。 您可以在管道代码中使用它而不是addBadge。 或者,它可能会提供一条线索,帮助管道addBadge正常工作

添加徽章的Groovy PostBuild代码:

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

manager.addBadge("warning.gif", "Warning test")
manager.addWarningBadge("other warning test")
e、 g.向来自另一个作业的作业添加徽章的Groovy代码: 当作业的版本与最新版本不匹配时,将其标记为已过时。 我给出了这个示例代码,因为这是我当前使用的,并且它是有效的

import hudson.model.*
import groovy.json.JsonSlurper
import org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildAction
//import org.jvnet.hudson.plugins.groovypostbuild.*
import org.jenkinsci.plugins.buildtriggerbadge.BuildTriggerBadgeAction;

def jobList = [ "job1", "job2" ]

def latestFile = downloadDir + "/latest_version.txt"
try {
  println "read file:" + latestFile
  vLATEST = new File(latestFile).text.trim().replaceAll('-','.')
  println vLATEST
} catch (MissingPropertyException|FileNotFoundException e) { 
  vLATEST = "LATEST version file not found"
  vLATEST = "unknown"
}

for(item in Hudson.instance.items) {

  v = "unknown"

  println "ITEM NAME: " + item.getDisplayName()
  println "ITEM DESC: " + item.getDescription()
  if (item.lastBuild) {
    try {
      println "item.WORKSPACE:" + item.WORKSPACE
      println "item.lastBuild.workspace:" + item.lastBuild.workspace;
      vfilename = item.lastBuild.workspace.toString()+"/VERSION.txt"
      v = new File(vfilename).text.trim()
      println v
    } catch (MissingPropertyException|FileNotFoundException e) { 
      // workspace or file not found
      v = "version file not found"
    }
    //currentBuild.setDescription(desc)
  }
  //println item.getDescriptorByName()

  if (item.name in jobList && item.lastBuild) {
    // delete old/other badges
    for(action in item.lastBuild.badgeActions) {
      //println "action:" + action
      //https://javadoc.jenkins.io/hudson/model/Action.html
      if(action instanceof GroovyPostbuildAction) {  // this is safer anyway
        println "action is instanceof GroovyPostbuildAction, remove action:" + action +
            " ts:" + action.toString() +
            " dn:" + action.getDisplayName()
        item.lastBuild.actions.remove(action)
        item.lastBuild.save()
      }
    }

    //item.lastBuild.setDescription(item.lastBuild.description + "\n" + "test set description VERSION:" + v)

    println "check version. vLATEST:" + vLATEST + ", v:" + v
    if (!(vLATEST == "unknown") && !(v.contains(vLATEST))) {
      println "version is not unknown OR does not match so BADGE IT mark build as OLD. vLATEST:" + vLATEST + ", v:" + v
      // badge it badge it badge it badge it badge it badge it badge it badge it badge it badge it badge it badge it
      text = "OLD VERSION: " + v
      item.lastBuild.getActions().add(GroovyPostbuildAction.createShortText(text, "yellow", "grey", "1px", "darkgrey"));
    } else {
      println "vLATEST:" + vLATEST + " is in v:" + v + " so not marking the build as old."

    }
    // https://javadoc.jenkins.io/plugin/groovy-postbuild/org/jvnet/hudson/plugins/groovypostbuild/GroovyPostbuildRecorder.BadgeManager.html#addShortText-java.lang.String-      
  }

}

参考:


我认为这是jenkins monitor视图中的一个错误,没有显示徽章

但是,如果您使用该方法

addShortText (text: "ExampleText", background: "red", border: "1", borderColor: "black", color: "black")
将显示文本