Skip to content

Allow empty valued variables without ignoring enviroment vars substitution#2665

Merged
timja merged 12 commits intojenkinsci:masterfrom
PereBueno:empty-vars-exporting
Apr 17, 2025
Merged

Allow empty valued variables without ignoring enviroment vars substitution#2665
timja merged 12 commits intojenkinsci:masterfrom
PereBueno:empty-vars-exporting

Conversation

@PereBueno
Copy link
Copy Markdown
Contributor

@PereBueno PereBueno commented Apr 9, 2025

fixes: #2658

Changes export behaviour for global environment variables. Now empty env vars will be exported as empty values instead of key without value as they were until now.

env:
  - key: "FOO"
    value: ""

No change when configuring, behaviour is the same as before this PR.

Additinally, added a test covering varlues with environment variable resolution.

Your checklist for this pull request

🚨 Please review the guidelines for contributing to this repository.

  • Make sure you are requesting to pull a topic/feature/bugfix branch (right side) and not your master branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or in Jenkins JIRA
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Did you provide a test-case? That demonstrates feature works or fixes the issue.

@PereBueno PereBueno marked this pull request as ready for review April 9, 2025 14:21
@PereBueno PereBueno requested a review from a team as a code owner April 9, 2025 14:21
value: BAR
- key: FOO2
value: ""
- key: FOO3
Copy link
Copy Markdown
Member

@jglick jglick Apr 9, 2025

Choose a reason for hiding this comment

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

This (FOO3) just looks like a user error to me ⇒ the bundle should be rejected.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

UI allows to save an empty env var (regardless why would someone want that), so theoretically configuration as code should allow creating that configuration too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am talking about FOO3 (null) not FOO2 (empty).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's the point in allowing importing the exported yaml.
Empty vars will still be exported with no value, so it's either allowing keys without a value when importing or changing the export (which was discussed here).
I think we all agree that would be the optimal solution, but when testing that it impacted exports from several plugins, so that's not what we're trying to cover with this change

Copy link
Copy Markdown
Member

@timja timja Apr 10, 2025

Choose a reason for hiding this comment

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

the point is that

- key: FOO
   (no value)

is invalid and should not be allowed (unless it works right now and this is just testing something pre-existing)

a null env var value is invalid.
an empty string env var uncommon, but I guess

so ok:

- key: FOO
  value: ""

not ok:

- key: FOO

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we not just limit the behavioral change to this setting, leaving other misbehaving plugins for another day?

Copy link
Copy Markdown
Member

@timja timja Apr 14, 2025

Choose a reason for hiding this comment

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

Looks do-able from a quick look, something similar to this on CNode and then allow setting the value when you construct it.

Not sure how easy it would be to integrate when using databoundconfigurator though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm trying that, with no luck for the moment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(my link was missing added now)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated be00ec1:

  • Removed the changes when configuring, so importing null vars is not supported
  • Added a false by default flag to CNode to allow printing when empty and setting it to trtue only for non null env vars

Will update PR description accordingly

@PereBueno PereBueno requested review from jglick and timja April 15, 2025 08:59
Copy link
Copy Markdown
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

LGTM

@timja
Copy link
Copy Markdown
Member

timja commented Apr 15, 2025

Related test failing on Java 21

@PereBueno
Copy link
Copy Markdown
Contributor Author

Related test failing on Java 21

Forgot to remove test condition from previous implementation 😅

Fixed now

@timja timja merged commit ddc0d36 into jenkinsci:master Apr 17, 2025
17 checks passed
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.

Empty environment variables are exported without value

5 participants