Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-50442

Adding removeBadge(icon) and removeAllBadges() methods to remove existing badges

    • Icon: New Feature New Feature
    • Resolution: Fixed
    • Icon: Minor Minor
    • badge-plugin
    • jenkins 2.113
      badge-plugin 1.2

      The new DSL addBadge() allow to create a new badge directly from the pipeline.

      How to remove it later on ? In our workflow, there are several pauses waiting for user input, and at each stage we are displaying a different icons (removing previous one and adding a different one).

      Here a workaround:

      def removeBadges(RunWrapper build, String icon = null) {
       List<Action> actions = build.getRawBuild().getActions()
       List<BuildBadgeAction> badgeActions = build.getRawBuild().getActions(BuildBadgeAction.class)
       for(BuildBadgeAction action : badgeActions) {
        if (icon == null || action.iconPath == icon) {
         actions.remove(action)
        }
       }
      }
      

      Would need a removeBadge(icon) and removeAllBadges() methods to do it directly in the pipeline.
       

          [JENKINS-50442] Adding removeBadge(icon) and removeAllBadges() methods to remove existing badges

          Jean-Paul G created issue -
          Jean-Paul G made changes -
          Description Original: The new DSL addBadge() allow to create a new badge directly from the pipeline.

          How to remove it later on ? In our workflow, there are several pauses waiting for user input, and at each stage we are displaying a different icons (removing previous one and adding a different one).

          I'm was so far doing something like:
          {code:java}
          def removeBadges(RunWrapper build) {
           List<Action> actions = build.getRawBuild().getActions()
           List<GroovyPostbuildAction> badgeActions = build.getRawBuild().getActions(GroovyPostbuildAction.class)
           for(GroovyPostbuildAction action : badgeActions) {
            actions.remove(action)
           }
          }

          {code}
          Would need a *removeBadge(icon)* and *removeAllBadges()* methods to do it directly in the pipeline.

           
          New: The new DSL addBadge() allow to create a new badge directly from the pipeline.

          How to remove it later on ? In our workflow, there are several pauses waiting for user input, and at each stage we are displaying a different icons (removing previous one and adding a different one).

          Here a workaround:
          {code:java}
          def removeBadges(RunWrapper build, String icon = null) {
           List<Action> actions = build.getRawBuild().getActions()
           List<BuildBadgeAction> badgeActions = build.getRawBuild().getActions(BuildBadgeAction.class)
           for(BuildBadgeAction action : badgeActions) {
            if (icon == null || action.iconPath == icon) {
             actions.remove(action)
            }
           }
          }
          Would need a
          {code}
          *removeBadge(icon)*
          {code:java}
           and
          {code}
          *removeAllBadges()*
          {code:java}
           methods to do it directly in the pipeline.
          {code}
           
          Jean-Paul G made changes -
          Description Original: The new DSL addBadge() allow to create a new badge directly from the pipeline.

          How to remove it later on ? In our workflow, there are several pauses waiting for user input, and at each stage we are displaying a different icons (removing previous one and adding a different one).

          Here a workaround:
          {code:java}
          def removeBadges(RunWrapper build, String icon = null) {
           List<Action> actions = build.getRawBuild().getActions()
           List<BuildBadgeAction> badgeActions = build.getRawBuild().getActions(BuildBadgeAction.class)
           for(BuildBadgeAction action : badgeActions) {
            if (icon == null || action.iconPath == icon) {
             actions.remove(action)
            }
           }
          }
          Would need a
          {code}
          *removeBadge(icon)*
          {code:java}
           and
          {code}
          *removeAllBadges()*
          {code:java}
           methods to do it directly in the pipeline.
          {code}
           
          New: The new DSL addBadge() allow to create a new badge directly from the pipeline.

          How to remove it later on ? In our workflow, there are several pauses waiting for user input, and at each stage we are displaying a different icons (removing previous one and adding a different one).

          Here a workaround:
          {code:java}
          def removeBadges(RunWrapper build, String icon = null) {
           List<Action> actions = build.getRawBuild().getActions()
           List<BuildBadgeAction> badgeActions = build.getRawBuild().getActions(BuildBadgeAction.class)
           for(BuildBadgeAction action : badgeActions) {
            if (icon == null || action.iconPath == icon) {
             actions.remove(action)
            }
           }
          }
          {code}
          Would need a *removeBadge(icon)* and *removeAllBadges()* methods to do it directly in the pipeline.
            
          Marc Brugger made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]
          Marc Brugger made changes -
          Status Original: In Progress [ 3 ] New: In Review [ 10005 ]
          Marc Brugger made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: In Review [ 10005 ] New: Resolved [ 5 ]
          Marc Brugger made changes -
          Status Original: Resolved [ 5 ] New: Closed [ 6 ]

            bakito Marc Brugger
            jguigui Jean-Paul G
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: