jenkinsci / badge-plugin

Jenkins Badge plugin
https://plugins.jenkins.io/badge/
MIT License
32 stars 43 forks source link

Can't removeBadge(id) for a createSummary(icon, id, txt) entry #45

Closed jimklimov closed 1 year ago

jimklimov commented 2 years ago

Describe the bug I am trying to add a rolling update of my build status, by posting short texts into the build history column and into the summary page. These texts are posted with an ID, so I would remove the older entry when I post a new one.

In case of createSummary(), the README does imply that the id field allows to remove the entry later - but at least removeBadge() did not work for it (works for the "usual" badges though not instantaneously - sometimes several older entries remain and then disappear all at once).

To Reproduce Pipeline runs a loop, each cycle of which calls this logic at the end to update the progress info:

            this.script.removeBadges(id: "Build-progress-summary@" + this.objectID)
            this.script.createSummary(icon: 'info.gif', text: txt, id: "Build-progress-summary@" + this.objectID)

Expected behavior I expected the older summary entry to disappear and only the latest to be seen.

Screenshots

As seen in the build summary page (never mind the blank icon areas):

jenkins-badge--createSummary-not-removed

Additional context I wonder if this is linked to the summary step creating a different kind of object (than the left-column badges that can be removed). Notably, only one XML tag with the ID of a "badge" is present at any time as seen in the build.xml file, but many tags with the same ID of a "summary" are present:

// "Usual" badge from addShortText()
    <com.jenkinsci.plugins.badge.action.BadgeAction plugin="badge@1.9">
      <text>Running 378 &apos;slow build&apos; dynamatrix stages</text>
      <color>#000000</color>
      <background>#FFFF00</background>
      <border>1px</border>
      <borderColor>#C0C000</borderColor>
    </com.jenkinsci.plugins.badge.action.BadgeAction>

...

    <com.jenkinsci.plugins.badge.action.BadgeSummaryAction plugin="badge@1.9">
      <id>Build-progress-summary@2680ed6</id>
      <iconPath>info.gif</iconPath>
      <summaryText>Build in progress: [STARTED:5]</summaryText>
    </com.jenkinsci.plugins.badge.action.BadgeSummaryAction>

...

    <com.jenkinsci.plugins.badge.action.BadgeAction plugin="badge@1.9">
      <id>Build-progress-badge@2680ed6</id>
      <iconPath>/plugin/badge/images/info.gif</iconPath>
      <text>Build in progress: [STARTED:126, COMPLETED:111, SUCCESS:111]</text>
      <color>#000000</color>
      <background>#FFFF00</background>
      <border>1px</border>
      <borderColor>#C0C000</borderColor>
    </com.jenkinsci.plugins.badge.action.BadgeAction>

...

    <com.jenkinsci.plugins.badge.action.BadgeSummaryAction plugin="badge@1.9">
      <id>Build-progress-summary@2680ed6</id>
      <iconPath>info.gif</iconPath>
      <summaryText>Build in progress: [STARTED:129, COMPLETED:114, SUCCESS:113, UNSTABLE:1]</summaryText>
    </com.jenkinsci.plugins.badge.action.BadgeSummaryAction>
vilarion commented 1 year ago

Hi @jimklimov! If you are still looking for this, I found that removeSummaries(id:'some id') and removeSummaries() exist and work for summaries like removeBadges works for badges. These seem to be missing in the documentation, though.