Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-62305] Make password parameters work with the build step in Jenkins 2.236+ #46

Merged
merged 12 commits into from
Aug 4, 2020

Conversation

dwnusbaum
Copy link
Member

See JENKINS-62305.

jenkinsci/jenkins#4630 changed the @DataBoundConstructor for PasswordParameterValue so that one of its parameters is a Secret, but Secret is not supported by data binding via DescribableModel in structs.

This PR uses CustomDescribableModel to maintain compatibility with existing uses of the build step with password parameters, and adds documentation explaining that credentials should be preferred over password parameters going forward.

TODO: Do we want to add a runtime warning (e.g. message in the build log) any time a password parameter is used with the build step? My understanding is that while password parameters are not ideal, they are not completely broken, so I am a little hesitant to add a warning if the issues are relatively minor.

Other things that are broken and that this PR does not attempt to fix:

@@ -8,6 +8,24 @@

Adds the Pipeline `build` step, which triggers builds of other jobs.

### Passing secret values to other jobs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention also in help-parameters.html.

@dwnusbaum
Copy link
Member Author

FWIW, I realized that snippet generation for password parameters is already broken even on older versions of Jenkins. You can fix it using customUninstantiate, but even if you fix the output this warning is logged, essentially because only BuildTriggerStep implements CustomDescribableModel, not PasswordParameterValue itself:

java.lang.ClassCastException: hudson.model.PasswordParameterValue.value expects class java.lang.String but received class hudson.util.Secret
	at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:492)
	at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:409)
	at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:329)
Caused: java.lang.IllegalArgumentException: Could not instantiate {name=param-name, value=secret} for hudson.model.PasswordParameterValue
	at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:334)
	at org.jenkinsci.plugins.structs.describable.DescribableModel.uninstantiate2(DescribableModel.java:672)
	at org.jenkinsci.plugins.structs.describable.DescribableModel.uninstantiate2_(DescribableModel.java:752)
	at org.jenkinsci.plugins.structs.describable.DescribableParameter.uncoerce(DescribableParameter.java:196)
	at org.jenkinsci.plugins.structs.describable.DescribableParameter.uncoerce(DescribableParameter.java:190)
	at org.jenkinsci.plugins.structs.describable.DescribableParameter.inspect(DescribableParameter.java:142)
	at org.jenkinsci.plugins.structs.describable.DescribableModel.uninstantiate2(DescribableModel.java:655)
	at org.jenkinsci.plugins.structs.describable.DescribableModel.uninstantiate2_(DescribableModel.java:752)
	at org.jenkinsci.plugins.workflow.steps.StepDescriptor.uninstantiate(StepDescriptor.java:252)
	at org.jenkinsci.plugins.workflow.cps.Snippetizer.object2Groovy(Snippetizer.java:139)
	at org.jenkinsci.plugins.workflow.cps.Snippetizer.step2Groovy(Snippetizer.java:81)
	at org.jenkinsci.plugins.workflow.cps.SnippetizerTester.assertRoundTrip(SnippetizerTester.java:91)
	at org.jenkinsci.plugins.workflow.support.steps.build.BuildTriggerStepTest.snippetizerRoundTrip(BuildTriggerStepTest.java:588)
	...

Even so, at least snippet generation works with that patch, so I'll push it to the PR branch.

@dwnusbaum dwnusbaum marked this pull request as ready for review July 31, 2020 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants