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-75361] Consider Closure.resolveStrategy to reduce false positives #997

Merged
merged 3 commits into from
Mar 4, 2025

Conversation

dwnusbaum
Copy link
Member

@dwnusbaum dwnusbaum commented Mar 4, 2025

A user comment in JENKINS-75361 that has since been edited away, but is summarized in my comment, mentioned that #994 causes false positives for a relatively common pattern where assignments in closures are used as a DSL for building a map.

This PR adjusts the logic from that PR to consider Closure.resolveStrategy to try to reduce false positives a bit.

Testing done

See new automated test.

Submitter checklist

  • 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

@dwnusbaum dwnusbaum added the bug label Mar 4, 2025
@dwnusbaum dwnusbaum requested a review from jglick March 4, 2025 20:23
@dwnusbaum dwnusbaum requested a review from a team as a code owner March 4, 2025 20:23
Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

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

Nobody should use this idiom, but yeah if you did, this would give false positives.

@jglick jglick enabled auto-merge March 4, 2025 20:32
@dwnusbaum
Copy link
Member Author

Nobody should use this idiom

Yes, but I have seen it so many times in support bundles that it seemed worth fixing.

@jglick jglick merged commit afbde6a into jenkinsci:master Mar 4, 2025
16 of 17 checks passed
@dwnusbaum dwnusbaum deleted the JENKINS-75361 branch March 4, 2025 22:14
@zbynek
Copy link
Contributor

zbynek commented Mar 5, 2025

Nobody should use this idiom,

But isn't it used in all declarative pipelines because of https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/a423189a7dff591fcd7ab6ed5290093f104a9e84/pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy#L137 ?

We're not using anything like

body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = map

in Jenkinsflie or pipeline library, yet I could reproduce the issue before this PR was released.

@jglick
Copy link
Member

jglick commented Mar 5, 2025

isn't it used in all declarative pipelines

Right, I meant use it directly.

I had thought that #995 handled the false positives from Declarative, but if this was also required, then great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants