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

Make params map immutable #542

Merged
merged 2 commits into from
Jul 11, 2022
Merged

Conversation

nre-ableton
Copy link
Contributor

The params map is also immutable on a real Jenkins instance, so code
shouldn't be allowed to modify it directly here, either.

Fixes #528.

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

A Jenkins build always has parameters, even if the job is not
parameterized. In such cases, params will be an empty map.
The params map is also immutable on a real Jenkins instance, so code
shouldn't be allowed to modify it directly here, either.
@nre-ableton nre-ableton merged commit a191fbf into master Jul 11, 2022
@nre-ableton nre-ableton deleted the nre/master/528-unmodifiable-params branch July 11, 2022 16:33
@gulyas-istvan-netlock-hu

Hello @nre-ableton ,
In declarative pipelines the choices clause always throws exception, and impossible to test production code which working on prod Jenkins :(

The clause without parameters unusable there, because the choice parameters are immutable later.

The feature is not simulating Jenkins now :(

java.lang.UnsupportedOperationException
	at java.base/java.util.Collections$UnmodifiableMap.put(Collections.java:1457)
...
	at com.lesfurets.jenkins.unit.declarative.ParametersDeclaration.setParams(ParametersDeclaration.groovy:9)
	at com.lesfurets.jenkins.unit.declarative.ParametersDeclaration$setParams.callCurrent(Unknown Source)
...
	at com.lesfurets.jenkins.unit.declarative.ParametersDeclaration.choice(ParametersDeclaration.groovy:19)

@nre-ableton
Copy link
Contributor Author

@gulyas-istvan-netlock-hu Can you please provide an example declarative pipeline that fails since this change?

@nre-ableton
Copy link
Contributor Author

BTW, I think I have a fix for this, but I'd like a failing test to go along with the change.

@gulyas-istvan-netlock-hu

A simple example I wrote into the new PR chat: #546 (comment)

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.

Can "params" be defined as a java.util.Collections$UnmodifiableMap instead of a regular map?
2 participants