Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to badge-plugin 2.x #81

Merged
merged 14 commits into from
Oct 12, 2024

Conversation

strangelookingnerd
Copy link
Contributor

@strangelookingnerd strangelookingnerd commented Sep 18, 2024

Restores compatibility with latest badge-plugin version. See discussion in jenkinsci/badge-plugin#189

This also updates the baseline to 2.440.x

Testing done

Ran existing tests without issue. I did only try a limited set of manual UI tests, a second pair of eyes would be appreciated.

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

* new baseline 2.440.x
MarkEWaite added a commit to MarkEWaite/groovy-postbuild-plugin that referenced this pull request Sep 21, 2024
The dependee plugin binary causes lots of noise when the JenkinsRule test
is starting.  The noise includes many reports of plugins that cannot be
loaded because they require newer dependencies, even though the newest
dependencies are already included as test scoped dependencies in the
pom file.  I assume that is due to the ancient Jenkins version that is
referenced in the dependee plugin binary.  The dependee plugin was built
in 2013 and is not part of the Jenkins update center.

Use the script security plugin instead because it is already a dependency
and does not require separate script approval.

Detected the test noise while evaluating pull request:

* jenkinsci#81

The test was passing but was generating many failure messages because
badge plugin 1.13 could not be loaded.  Those messages no longer happen
with this test change.

Adds more assertions on the BadgeAction object for good measure.
MarkEWaite added a commit that referenced this pull request Sep 21, 2024
The dependee plugin binary causes lots of noise when the JenkinsRule test
is starting.  The noise includes many reports of plugins that cannot be
loaded because they require newer dependencies, even though the newest
dependencies are already included as test scoped dependencies in the
pom file.  I assume that is due to the ancient Jenkins version that is
referenced in the dependee plugin binary.  The dependee plugin was built
in 2013 and is not part of the Jenkins update center.

Use the script security plugin instead because it is already a dependency
and does not require separate script approval.

Detected the test noise while evaluating pull request:

* #81

The test was passing but was generating many failure messages because
badge plugin 1.13 could not be loaded.  Those messages no longer happen
with this test change.

Adds more assertions on the BadgeAction object for good measure.
@MarkEWaite MarkEWaite added the bug Incorrect or flawed behavior label Sep 21, 2024
@MarkEWaite
Copy link
Contributor

MarkEWaite commented Sep 22, 2024

Thanks for the pull request. I've successfully compared the results of the badge methods:

  • addBadge
  • addBadge-3 (single test case)
  • addErrorBadge
  • addInfoBadge
  • addShortText
  • addShortText-5 (single test case)
  • addShortText-notBuilt
  • addWarningBadge

I've successfully compared the results of the build method steps:

  • buildUnstable
  • buildAborted
  • buildFailure
  • buildSuccess

The createSummary method showed some significant differences between the badge 1.13 version and the badge 2.1 version

Badge 1.13

Pipeline:

pipeline {
    agent any
    stages {
        stage('createSummary and hyperlink') {
            steps {
                script {
                    icon = 'warning.gif'
                    text = 'My text'
                    escapeHtml = false
                    text = text + ' <a href="https://github.com">github.com</a>'
                    def summary = manager.createSummary(icon)
                    summary.appendText(text)
                    // summary.appendText(text, escapeHtml)
                        // summary.appendText(text, escapeHtml, bold, italic, color)
                }
            }
        }
    }
}

Build page containing the summary:

badge-1 13-layout

Badge 2.1

Same Pipeline script:

pipeline {
    agent any
    stages {
        stage('createSummary and hyperlink') {
            steps {
                script {
                    icon = 'warning.gif'
                    text = 'My text'
                    escapeHtml = false
                    text = text + ' <a href="https://github.com">github.com</a>'
                    def summary = manager.createSummary(icon)
                    summary.appendText(text)
                    // summary.appendText(text, escapeHtml)
                        // summary.appendText(text, escapeHtml, bold, italic, color)
                }
            }
        }
    }
}

Build page containing the summary:

badge-2 1-layout

The hyperlink is not rendered as a hyperlink in the new code and the image is rendered as a gif instead of being converted to an SVG.

If I switch the markup formatter in the new code from "Plain text" to "Safe HTML", then the hyperlink is shown the same in 2.1 as it was in 1.13.

@MarkEWaite
Copy link
Contributor

The use of the Jenkins markup formatter in the new code allows me to install the Markdown formatter plugin and use Markdown in my summaries instead of using HTML. I'm not sure what fraction of users are already using the safe HTML markup formatter on the Jenkins controller where they use createSummary.

Is it feasible to have a compatibility mode that renders HTML in summaries as HTML rather than breaking user summaries on controllers that are using the plain text markup formatter?

@MarkEWaite
Copy link
Contributor

Another minor difference that I've detected is visible when hovering over the badge in the build history. The hover text from badge 1.13 fits the text while the hover text for badge 2.1 has an additional empty line inside it.

Badge 1.13

badge-1 13-hover-text

Badge 2.1

badge-2 1-hover-text

The difference seems to be purely cosmetic, but since I detected it, I thought that I should note it here.

@strangelookingnerd
Copy link
Contributor Author

Is it feasible to have a compatibility mode that renders HTML in summaries as HTML rather than breaking user summaries on controllers that are using the plain text markup formatter?

To me the behavior of the 1.x version is highly questionable in terms of security as it would allow to completely bypass HTML sanitation. Which was the main reason why I wanted to remove it.

I could imagine something like „if plaintext formatter is configured but safe html formatter is available use it if a configuration is set“ - but that would involve manual tasks (setting a environment flag, configuration, and the likes) which by the end would be similar to changing Jenkins global markup formatter.

So I guess what I’m trying to say that it would definitely not be impossible but it goes against so many principles of software security that I can not bring myself to like the idea 😅 Maybe there is another approach?

@strangelookingnerd
Copy link
Contributor Author

Another minor difference that I've detected is visible when hovering over the badge in the build history. The hover text from badge 1.13 fits the text while the hover text for badge 2.1 has an additional empty line inside it.

That’s odd, I will look into it.

MarkEWaite added a commit to MarkEWaite/docker-lfs that referenced this pull request Sep 22, 2024
@strangelookingnerd
Copy link
Contributor Author

Another minor difference that I've detected is visible when hovering over the badge in the build history. The hover text from badge 1.13 fits the text while the hover text for badge 2.1 has an additional empty line inside it.

That’s odd, I will look into it.

I can not reproduce this on my end using Jenkins 2.440.3 and 2.462.2 with neither Firefox, Chrome or Edge.

@MarkEWaite
Copy link
Contributor

I can not reproduce this on my end using Jenkins 2.440.3 and 2.462.2 with neither Firefox, Chrome or Edge.

Thanks for trying. I cannot duplicate it either. I recreated my installation from the git repository where I'm tracking its details and the problem is no longer visible to me. The screenshots are real, but I don't have the steps that will duplicate the issue. Let's ignore that cosmetic issue until I find a way to duplicate it.

@MarkEWaite
Copy link
Contributor

MarkEWaite commented Sep 23, 2024

To me the behavior of the 1.x version is highly questionable in terms of security as it would allow to completely bypass HTML sanitation. Which was the main reason why I wanted to remove it.

I'm not aware of any security issue with the 1.x version, but I understand the desire to use an existing, standard component to process the HTML markup instead of using something that is specific to the Badge plugin.

So I guess what I’m trying to say that it would definitely not be impossible but it goes against so many principles of software security that I can not bring myself to like the idea 😅 Maybe there is another approach?

Would it be enough if we added documentation to the README that describes the alternatives that are now available thanks to this change?

I think there are multiple scenarios that we need to describe:

  • Existing installation of badge 1.13 and matching Groovy post-build plugin release with default markup formatter
  • Existing installation of badge 1.13 and matching Groovy post-build plugin release with safe HTML markup formatter
  • Existing installation of badge 1.13 and matching Groovy post-build plugin release with Markdown markup formatter
  • Upgraded from badge 1.13 to badge 2.1 with default markup formatter
  • Upgraded from badge 1.13 to badge 2.1 with safe HTML markup formatter
  • Upgraded from badge 1.13 to badge 2.1 with Markdown markup formatter
  • New installation of badge 2.1 and this pull request of Groovy post-build plugin release with default markup formatter
  • New installation of badge 2.1 and this pull request of Groovy post-build plugin release with safe HTML markup formatter
  • New installation of badge 2.1 and this pull request of Groovy post-build plugin release with Markdown markup formatter

@strangelookingnerd
Copy link
Contributor Author

Would it be enough if we added documentation to the README that describes the alternatives that are now available thanks to this change?

Sounds reasonable to me, I will write something up for the Release Notes / Readme.

@xmapst
Copy link

xmapst commented Sep 24, 2024

该插件什么时候可以正常工作

@MarkEWaite
Copy link
Contributor

MarkEWaite commented Sep 24, 2024

该插件什么时候可以正常工作

When will the plugin work properly?

The plugin will work properly if you install badge plugin 1.13 instead of badge plugin 2.1. Use the Jenkins plugin manager "Advanced Settings" to upload badge plugin 1.13 from the URL:

If you must have badge plugin 2.1, then you'll need to use the pre-release build that is available from the "Incrementals Publisher" section of the GitHub checks. That is also a great way for you to help test the pre-release of the plugin. If you'd rather wait for others to test the pre-release of the plugin, then you'll need to downgrade the badge plugin to 1.13.

@splitt3r
Copy link

该插件什么时候可以正常工作
When will the plugin work properly?

The plugin will work properly if you install badge plugin 1.13 instead of badge plugin 2.1. Use the Jenkins plugin manager "Advanced Settings" to upload badge plugin 1.13 from the URL:

* https://updates.jenkins.io/download/plugins/badge/1.13/badge.hpi

If you must have badge plugin 2.1, then you'll need to use the pre-release build that is available from the "Incrementals Publisher" section of the GitHub checks. That is also a great way for you to help test the pre-release of the plugin. If you'd rather wait for others to test the pre-release of the plugin, then you'll need to downgrade the badge plugin to 1.13.

Thank you for the great work 👍🏻 i installed the pre release version and it works great so far

@strangelookingnerd
Copy link
Contributor Author

Sounds reasonable to me, I will write something up for the Release Notes / Readme.

I updated the release notes( linked in the README), adding a section for troubleshooting: https://github.com/jenkinsci/badge-plugin/releases/tag/badge-2.0

Once this PR is merged and released I'd also add the version compatibility information.

@jimklimov
Copy link

Just wanted to p0st about a broken addShortText() following an upgrade, but you've beat me to it witha fix brewing. Kudos! :)

Also:   org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: 52bf183a-d532-4446-9fb0-0c20b46680d8
13:43:36  java.lang.NoSuchMethodError: 'com.jenkinsci.plugins.badge.action.BadgeAction com.jenkinsci.plugins.badge.action.BadgeAction.createShortText(java.lang.String)'
13:43:36  	at PluginClassLoader for groovy-postbuild//org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder$BadgeManager.addShortText(GroovyPostbuildRecorder.java:150)
...

@MarkEWaite
Copy link
Contributor

Just wanted to p0st about a broken addShortText() following an upgrade, but you've beat me to it with a fix brewing.

Can you confirm that the pull request build addresses the issue and does not cause unexpected harm?

pom.xml Outdated Show resolved Hide resolved
@MarkEWaite
Copy link
Contributor

MarkEWaite commented Oct 8, 2024

While comparing previous behavior and new behavior, I found a case where a Pipeline job previously included an icon and with the new code the icon is unavailable / broken.

Pipeline

pipeline {
    agent any
    stages {
        stage('createSummary and hyperlink') {
            steps {
                script {
                    icon = 'warning.gif'
                    text = 'My text'
                    escapeHtml = false
                    bold = true
                    italic = true
                    color = 'blue'
                    text = text + ' [GitHub](github.com) <a href="https://github.com">github.com</a>'
                    def summary = manager.createSummary(icon)
                    summary.appendText("1 - " + text + " - 1")
                    summary.appendText(" 2(escapeHtml=" + escapeHtml + ") - " + text + " - 2", escapeHtml)
                    summary.appendText(" 3 - " + text + " - 3", escapeHtml, bold, italic, color)
                    manager.createSummary("gear2.gif").appendText("<h2>Successfully deployed</h2>", false)
                }
            }
        }
    }
}

Badge 1.13 and postbuild 228.vcdb_cf7265066

creaetSummary-before

Badge 2.2 and postbuild from this pull request

createSummary-after

@MarkEWaite
Copy link
Contributor

@strangelookingnerd I'm at the point where I've found inconsistencies but not major incompatibilities. I think it is time to release the groovy postbuild plugin with the updated documentation that is included in this pull request and accept that users will likely report additional issues that need further changes.

Do you agree?

@MarkEWaite
Copy link
Contributor

I may have found a workaround for some of the cases of gif image quality. Several of the images from the original list of gif images have a matching SVG image in the /images/svgs/ directory.

  • delete - edit-delete.svg
  • error - error.svg
  • folder - folder.svg
  • save - save.svg
  • warning - warning.svg

The following gif images do not have an obvious replacement from the svgs directory:

  • completed
  • db_in
  • db_out
  • info
  • success

I think that the groovy-postbuild plugin could detect references to those known gif images and replace them with SVG references. Does that seem reasonable?

@strangelookingnerd
Copy link
Contributor Author

@strangelookingnerd I'm at the point where I've found inconsistencies but not major incompatibilities. I think it is time to release the groovy postbuild plugin with the updated documentation that is included in this pull request and accept that users will likely report additional issues that need further changes.

Do you agree?

Sorry for the late response. Yes I think it would be best to ship the changes now and wait for feedback in case there is more to fix.

@strangelookingnerd
Copy link
Contributor Author

I may have found a workaround for some of the cases of gif image quality. Several of the images from the original list of gif images have a matching SVG image in the /images/svgs/ directory.

* delete - edit-delete.svg

* error - error.svg

* folder - folder.svg

* save - save.svg

* warning - warning.svg

The following gif images do not have an obvious replacement from the svgs directory:

* completed

* db_in

* db_out

* info

* success

I think that the groovy-postbuild plugin could detect references to those known gif images and replace them with SVG references. Does that seem reasonable?

I was already thinking of doing that for the badge-plugin itself. Usage of SVG / symbols should be preferred in any case.
I could provide a PR once I find a solution that works.

@MarkEWaite MarkEWaite added breaking Breaks compatibility with previous releases and removed bug Incorrect or flawed behavior labels Oct 12, 2024
Include details of the markup formatters that have been tested and a
warning to existing users that they may need to enable the safe HTML
formatter.
@MarkEWaite MarkEWaite enabled auto-merge (rebase) October 12, 2024 21:47
@MarkEWaite
Copy link
Contributor

I've added documentation for markup formatters and have enabled auto-merge. It should merge and release once the CI job passes.

@MarkEWaite MarkEWaite merged commit f6e02a7 into jenkinsci:master Oct 12, 2024
15 of 16 checks passed
@strangelookingnerd strangelookingnerd deleted the upgrade_badge-plugin branch October 12, 2024 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Breaks compatibility with previous releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants