jenkinsci / badge-plugin

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

Badge link with POST #10

Closed steven-foster closed 4 years ago

steven-foster commented 6 years ago

I'd like to use badges to trigger other builds with parameters, which requires a POST to a particular URL. I can mostly do this with the HTML badge, but it would be neat to have a POST mode in the standard link badges too if possible.

bakito commented 6 years ago

Have you tried to add a html form as html?

steven-foster commented 6 years ago

Yes, it worked for the most part but the styling was a bit odd. The badge was placed on a newline. Maybe there's a workaround for that.

bakito commented 6 years ago

I don't know. If you provided me your pipeline script, I could have a look at it.

steven-foster commented 6 years ago

Here's what I have:

node() {
    def html = """<form method="post" name="parameters" action="/job/artifact_publish/buildWithParameters?BUILD_SELECTOR=${env.JOB_NAME}%23${env.BUILD_NUMBER}">
    <input name="statusCode" value="303" type="hidden" />
    <input type="image" src="/plugin/badge/images/save.gif" />
    </form>""".stripIndent()
    echo "hi"
    addHtmlBadge html: html
}
mucst commented 5 years ago

In my opinion triggering other builds is not something that one would necessarily expect from this plugin. A solution you showed is a good way to go.