Conversion of string parameters to objects in declarative vs. scripted pipelines

21 views
Skip to first unread message

Ullrich Hafner

unread,
Aug 12, 2025, 5:06:02 AMAug 12
to Jenkins Developers
In my workflow step I have a parameter of type hudson.model.Result
@DataBoundSetter
public void setRequiredResult(final Result requiredResult) {
this.requiredResult = requiredResult;
}
When this parameter is set in the snipped generator, then the snipped generator creates the parameter as
discoverReferenceBuild requiredResult: 'FAILURE‘ 
This works for scripted pipelines, but not for declarative pipelines. In declarative pipelines I get an error:
WorkflowScript: 43: Expecting "class hudson.model.Result" for parameter "requiredResult" but got "SUCCESS" of type class java.lang.String instead @ line 43, column 67.
Is there a way to provide a hint for declarative pipelines so that the conversion of String to Result is handled automatically?
As a workaround I am now adding a String parameter as well, but this seems to be not elegant. 
PR: https://github.com/jenkinsci/forensics-api-plugin/pull/614
Issue: https://issues.jenkins.io/browse/JENKINS-75846





Jesse Glick

unread,
Aug 12, 2025, 1:27:21 PMAug 12
to jenkin...@googlegroups.com
On Tue, Aug 12, 2025 at 5:06 AM Ullrich Hafner <ullrich...@gmail.com> wrote:
Is there a way to provide a hint for declarative pipelines so that the conversion of String to Result is handled automatically?
As a workaround I am now adding a String parameter as well, but this seems to be not elegant. 
I do not recall the details of why a `Result`-typed parameter works at all, but I would limit yourself to `String`. (Do not recall if `enum` works.)
Reply all
Reply to author
Forward
0 new messages