Skip to content

Parameters for build step are not handled properly #747

@famod

Description

@famod

Jenkins and plugins versions report

not relevant

What Operating System are you using (both controller, and any agents involved in the problem)?

not relevant

Reproduction steps

In some pipline under test:

build(job: 'foo', parameters: [
    string(name: 'BAR', value: 'test',
])

Expected Results

The call stack should have something like:

somePipeline.string({name=BAR, value=test})
somePipeline.build({job=foo, parameters=['test']})

(or whatever the matching toString representation of a string parameter within build would be)

Actual Results

The call stack actually only has a null parameter (second line):

somePipeline.string({name=BAR, value=test})
somePipeline.build({job=foo, parameters=[null]})

Anything else?

Looking at DeclarativePipelineTest:

helper.registerAllowedMethod('string', [Map], stringInterceptor)

and BasePipelineTest:

    def stringInterceptor = { Map desc->
        if (desc) {
            // we are in context of parameters { string(...)}
            if (desc.name) {
                addParam(desc.name, desc.defaultValue, false)
            }
            // we are in context of withCredentials([string()..]) { }
            if(desc.variable) {
                return desc.variable
            }
        }
    }

I'm under the impression that params for a build step are wrongly treated as params for the current pipeline under test.

PS: Same seems to apply to booleanParam.

My workaround:
helper.registerAllowedMethod("booleanParam", [Map], { map -> map['name'] + '=' + map['value'] })
helper.registerAllowedMethod("string", [Map], { map -> map['name'] + '=' + map['value'] })

Are you interested in contributing a fix?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions