jenkinsci / badge-plugin

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

addBadge does not take default parameters #11

Closed quasarea closed 6 years ago

quasarea commented 6 years ago

as described at https://jenkins.io/doc/pipeline/steps/badge/#addbadge-add-badge :

addBadge: Add Badge
    icon Type: String
    text  Type: String
    id (optional) Type: String
    link (optional) Type: String

but calling

addBadge("myicon","mytext") 

yields

Expected named arguments but got [/images/16x16/blue.png, blue]

named parameters works fine, but constructor with (string icon, string text, string id = null, string link = null) should be exposed - it works (such constructor when used via manager, i.e.:

manager.addBadge("myicon","mytext")
bakito commented 6 years ago

I'm not sure if that is possible for build step implementations. (At least, i don't know how)

quasarea commented 6 years ago

What I mean that I have working pipeline code:

if (BuildAvoided) {
    addBadge(icon: "/images/16x16/blue.png", text: queryResult)
 } else {
     addInfoBadge (queryResult)
}

and as you can see, addInfoBadge takes parameters directly, while addBadge requires named parameters. Both work fine without named parameters, when called with manager:

if (BuildAvoided) {
    manager.addBadge("/images/16x16/blue.png", queryResult)
 } else {
    manager.addInfoBadge (queryResult)
}

so there is some inconsistency

bakito commented 6 years ago

This inconsistency that you mention is a feature of the framework. The difference is, that addInfoBadge has only one single argument. The implementation then takes this argument for the single parameter.

https://github.com/jenkinsci/workflow-cps-plugin/blob/master/src/main/java/org/jenkinsci/plugins/workflow/cps/DSL.java#L530

If you have more than one argument, the framework needs the keys for them. otherwise an IllegalArgument Exception is thown. See: https://github.com/jenkinsci/workflow-cps-plugin/blob/master/src/main/java/org/jenkinsci/plugins/workflow/cps/DSL.java#L532

quasarea commented 6 years ago

Ok, thanks for explanation. Will use named arguments.