[JIRA] (JENKINS-60216) Pipeline Build Step should automatically convert mistyped parameters to the correct type where possible

22 views
Skip to first unread message

dnusbaum@cloudbees.com (JIRA)

unread,
Nov 19, 2019, 3:08:02 PM11/19/19
to jenkinsc...@googlegroups.com
Devin Nusbaum created an issue
 
Jenkins / Improvement JENKINS-60216
Pipeline Build Step should automatically convert mistyped parameters to the correct type where possible
Issue Type: Improvement Improvement
Assignee: Devin Nusbaum
Components: pipeline-build-step-plugin
Created: 2019-11-19 20:07
Priority: Minor Minor
Reporter: Devin Nusbaum

The Pipeline build step does not validate that the types of parameters passed to the step match the parameter types defined on the downstream job. This leads to situations like users passing a string parameter ("true") when a boolean parameter is expected, or a string parameter where a password is expected, etc.

 Parameterized-trigger plugin made a change long ago to automatically convert some kinds of parameter type mismatches, see https://github.com/jenkinsci/parameterized-trigger-plugin/pull/62.

The build step should be updated to perform the same conversion logic, and log a warning when such a conversion occurs.

In some cases, a conversion is not possible/sensible (i.e. converting a password parameter to a boolean parameter). The build step does not currently attempt to prevent these kinds of mismatches, and this issue is not about changing that behavior (but perhaps it would make sense to fail the build or log a warning when that happens, perhaps hidden behind an option or system property).

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

dnusbaum@cloudbees.com (JIRA)

unread,
Nov 19, 2019, 3:08:03 PM11/19/19
to jenkinsc...@googlegroups.com
Devin Nusbaum updated an issue
Change By: Devin Nusbaum
The Pipeline {{build}} step does not validate that the types of parameters passed to the step match the parameter types defined on the downstream job. This leads to situations like users passing a string parameter ("true") when a boolean parameter is expected, or a string parameter where a password is expected, etc.

  Parameterized-trigger plugin made a change long ago to automatically convert some kinds of parameter type mismatches, see https://github.com/jenkinsci/parameterized-trigger-plugin/pull/62.

The {{build}} step should be updated to perform the same conversion logic, and log a warning when such a conversion occurs.

In some cases, a conversion is not possible/sensible (i.e. converting a password parameter to a boolean parameter). The {{build}} step does not currently attempt to prevent these kinds of mismatches, and this issue is not about changing that behavior (but perhaps it would make sense to fail the build or log a warning when that happens, perhaps hidden behind an option or system property).
Add Comment Add Comment
 

dnusbaum@cloudbees.com (JIRA)

unread,
Nov 19, 2019, 3:10:11 PM11/19/19
to jenkinsc...@googlegroups.com
Devin Nusbaum started work on Improvement JENKINS-60216
 
Change By: Devin Nusbaum
Status: Open In Progress

dnusbaum@cloudbees.com (JIRA)

unread,
Nov 19, 2019, 3:10:12 PM11/19/19
to jenkinsc...@googlegroups.com

dnusbaum@cloudbees.com (JIRA)

unread,
Nov 26, 2019, 3:30:02 PM11/26/19
to jenkinsc...@googlegroups.com
 

A fix for this issue was just released in Pipeline: Build Step Plugin version 2.10.

Change By: Devin Nusbaum
Status: In Review Resolved
Resolution: Fixed
Released As: pipeline-build-step 2.10

smirky@smirky.net (JIRA)

unread,
Dec 9, 2019, 7:28:02 AM12/9/19
to jenkinsc...@googlegroups.com
Bogomil Vasilev commented on Improvement JENKINS-60216
 
Re: Pipeline Build Step should automatically convert mistyped parameters to the correct type where possible

Hi, I just updated to the latest version (2.10) and I found out about this new improvement the hard way, via a few of our pipeline jobs, calling some downstream jobs.

Until now, I was just doing something like this:

 

pipeline {
    parameters {
        choice(name: 'VAR_X', choices: ['1', '2', '3'], description: 'Pick something')
        string(name: 'VAR_Y', defaultValue: '', description: 'Specify Y')
	booleanParam(name: 'VAR_Z', defaultValue: false, description: 'True or False')
	choice(name: 'BUILD_PC', choices: ['bench1', 'bench2'], description: 'Specify a bench')
    }
	stages {
		stage('Compile') {
			when {
				expression { params.ONLY_PACKAGES == false && params.NO_COVERITY == true }
			}
			steps {
				catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
					script {
						result = build job: 'downstream_job', parameters: [
							string(name: 'VAR_X', value: "${params.VAR_X}"),
							string(name: 'VAR_Y', value: "${params.VAR_Y}",
							string(name: 'VAR_Z', value: "${params.VAR_Z}",
							// this is a Node variable in the downstream job
							string(name: 'BUILD_PC', value: "${params.BUILD_PC}")
						]
						}
					}
				}
			}
		}
	}
}

I stumbled upon the new feature that told me that it's converting my string downstream input from string to boolean parameter.
So I basically switched all the relevant string input variables to booleanParam(...), which resolved only that particular problem.

However, I also have a Node input variable, which so far I was not able to resolve:

The parameter 'BUILD_PC' did not have the type expected by downstream_job. Converting to Node.

So it is obvious that I'm getting this error, because the Downstream job is using the "Node" variable via the "Node and Label parameter plugin".
Thanks to the type conversion logic in the pipeline-build-step-plugin, I don't have an actual downside from this and it just gives me the quoted warning above.

Then again, I should somehow improve the expected type to be according to the downstream expectation.
Giving it node() is simply not working, as it gives me a stacktrace.
What is the correct way to fix this?

smirky@smirky.net (JIRA)

unread,
Dec 9, 2019, 8:08:02 AM12/9/19
to jenkinsc...@googlegroups.com
Bogomil Vasilev edited a comment on Improvement JENKINS-60216
Hi, I just updated to the latest version (2.10) and I found out about this new improvement the hard way, via a few of our pipeline jobs, calling some downstream jobs.

Until now, I was just doing something like this:

 
{code:java}

pipeline {
    parameters {
        choice(name: 'VAR_X', choices: ['1', '2', '3'], description: 'Pick something')
        string(name: 'VAR_Y', defaultValue: '', description: 'Specify Y')
booleanParam(name: 'VAR_Z', defaultValue: false, description: 'True or False')
choice(name: 'BUILD_PC', choices: ['bench1', 'bench2'], description: 'Specify a bench')
    }
stages {
  stage('Compile') {
   when {
    expression { params.ONLY_PACKAGES == false && params.NO_COVERITY == true
}
   }
   steps {
    catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
     script {
      result = build job: 'downstream_job', parameters: [
       string(name: 'VAR_X', value: "${params.VAR_X}"),
       string(name: 'VAR_Y', value: "${params.VAR_Y}",
       string(name: 'VAR_Z', value: "${params.VAR_Z}",
       // this is a Node variable in the downstream job
       string(name: 'BUILD_PC', value: "${params.BUILD_PC}")
      ]
      }
     }
    }
   }
  }
}
}{code}

I stumbled upon the new feature that told me that it's converting my string downstream input from string to boolean parameter.
So I basically switched all the relevant string input variables to booleanParam(...), which resolved only that particular problem.

However, I also have a Node input variable, which so far I was not able to resolve:
{quote}The parameter 'BUILD_PC' did not have the type expected by downstream_job. Converting to Node.
{quote}
So it is obvious that I'm getting this error, because the Downstream job is using the "Node" variable via the "[Node and Label parameter plugin|https://wiki.jenkins-ci.org/display/JENKINS/NodeLabel+Parameter+Plugin]".
Thanks to the type conversion logic in the [pipeline-build-step-plugin|https://issues.jenkins-ci.org/issues/?jql=project+%3D+JENKINS+AND+component+%3D+pipeline-build-step-plugin], I don't have an actual downside from this and it just gives me the quoted warning above.


Then again, I should somehow improve the expected type to be according to the downstream expectation.
Giving it node() is simply not working, as it gives me a stacktrace.
What is the correct way to fix this?

dnusbaum@cloudbees.com (JIRA)

unread,
Dec 9, 2019, 10:15:03 AM12/9/19
to jenkinsc...@googlegroups.com

Bogomil Vasilev In all cases, your builds continued working, right? The problem was just that you started to see a warning telling you that the parameter types were mismatched? Or did the builds where the downstream job was a node parameter start failing?

If your builds where the downstream job was using a node parameter were working before the fix, then maybe you could just switch the downstream job to have a string parameter instead (which would match the behavior from before this change would made), and if the builds started failing after the fix, then that is definitely what you should do. Otherwise, you can safely ignore the message in the build logs (maybe we could add a way to suppress the conversion messages if that is important).

As far as the right syntax to use so that no conversion is needed, it looks like Node and Label Parameter Plugin does not support Pipeline syntax natively (there is no symbol like "node" or "nodeParam" or anything), and perhaps there are other bugs that make it not work correctly (see PR 14, not sure what that is about), and it has some bug that makes the explicit data binding syntax not work either (JENKINS-47571), so I'm not totally sure how to use it correctly from Pipeline.

smirky@smirky.net (JIRA)

unread,
Dec 10, 2019, 10:09:04 AM12/10/19
to jenkinsc...@googlegroups.com

Yes, the builds continue working as usual. The Node plugin is also working, despite the conversion warning. I just don't know how to fix it in order to suppress the message from showing up.

max.matissek@beitragsservice.de (JIRA)

unread,
Dec 11, 2019, 5:41:03 AM12/11/19
to jenkinsc...@googlegroups.com

I want to Start a Jenkins-Job from a Pipeline with a "Extensible Choice Parameter" (SELECTEDVERSION).

Pipeline-Command: build job: 'testjob', parameters: [string(name: 'SELECTEDVERSION', value: artifactUrl)]

After the update of the "Pipeline: Build Step" Plugin to Verison 2.10 I get the Message "The parameter 'SELECTEDVERSION' did not have the type expected by testjob. Converting to Extensible Choice". What should I use instead of "string"?

dnusbaum@cloudbees.com (JIRA)

unread,
Jan 10, 2020, 12:08:02 PM1/10/20
to jenkinsc...@googlegroups.com

Bogomil Vasilev If your builds were working before the change, then you should be able to just change the type of the parameter on the downstream job to a string parameter so that no conversion happens, since that is what the previous behavior would have been (there was no conversion previously, so you were just passing a string parameter, which the downstream job apparently handles correctly, so I don't think the triggered builds were actually using the Node and Label Parameter Plugin, you just thought they were (this doesn't apply if you were also building the downstream job via the UI, since I think node and label parameters would work in that context)). If you want to keep use the Node and Label Parameter Plugin, then I would start watching and vote on JENKINS-43720 and JENKINS-47571.

Max Matissek I think the Extensible Choice Parameter Plugin is a special case, and we should still convert the parameters for them but not log a warning, similarly to what is done now for regular Choice Parameters. Can you please file a new bug for that issue?

max.matissek@beitragsservice.de (JIRA)

unread,
Jan 15, 2020, 5:52:09 AM1/15/20
to jenkinsc...@googlegroups.com

paul.thevenot@atos.net (JIRA)

unread,
Feb 19, 2020, 12:17:03 PM2/19/20
to jenkinsc...@googlegroups.com

I update to 2.10 as well and I've the same logs while passing parameters to child job using Active Choices Reactive Parameter. The parameter from the parent job is a string and so is the child parameter : "The parameter 'REPO' did not have the type expected by build-gradle. Converting to Active Choices Reactive Parameter.". What type should I use to pass my parameter instead of string?

paul.thevenot@atos.net (JIRA)

unread,
Feb 19, 2020, 12:19:03 PM2/19/20
to jenkinsc...@googlegroups.com
Paul Thevenot edited a comment on Improvement JENKINS-60216
I update to 2.10 as well and I've the same logs while passing parameters to child job using Active Choices Reactive Parameter. The parameter from the parent job is a string and so is the child parameter : "The parameter 'REPO' did not have the type expected by [build child - gradle|http://dev.sics.bull.fr/jenkins/ job /build-gradle/] . Converting to Active Choices Reactive Parameter.". What type should I use to pass my parameter instead of string?

paul.thevenot@atos.net (JIRA)

unread,
Feb 19, 2020, 12:19:04 PM2/19/20
to jenkinsc...@googlegroups.com
Paul Thevenot edited a comment on Improvement JENKINS-60216
I update 've updated to 2.10 as well and I've the same logs while passing parameters to child job using Active Choices Reactive Parameter. The parameter from the parent job is a string and so is the child parameter : "The parameter 'REPO' did not have the type expected by child-job. Converting to Active Choices Reactive Parameter.". What type should I use to pass my parameter instead of string?
Reply all
Reply to author
Forward
0 new messages