Allowing empty valued global variables in config file#2657
Allowing empty valued global variables in config file#2657timja merged 5 commits intojenkinsci:masterfrom
Conversation
| @Override | ||
| public Set<Attribute<EnvironmentVariablesNodeProperty, ?>> describe() { | ||
| Set<Attribute<EnvironmentVariablesNodeProperty, ?>> attrs = super.describe(); | ||
| attrs.add(new MultivaluedAttribute<EnvironmentVariablesNodeProperty, EnvironmentVariablesNodeProperty.Entry>( |
There was a problem hiding this comment.
Yes, if not using it env is not exported
- \"envVars\"
- toolLocation:
- locations:\n
- home: "/home/user/bin/git"
[....]
If I'm not wrong it's because we're extending BaseConfigurator which will take EnvVars as an scalar, while before this configurator it was read as a HeteroDescribableConfigurator.
There was a problem hiding this comment.
Would extending HeteroDescribableConfigurator work instead?
There was a problem hiding this comment.
I didn't test that, seems more complex than this approach.
I can do a test and check if we would be simplifying things
There was a problem hiding this comment.
Sorry, my fault, not Hetero, but DataBoundConfigurator.
Just changed it to use it, slightly simpler.
There was a problem hiding this comment.
Looks, much simpler and more like what I expected, thanks for sorting.
| import java.util.List; | ||
|
|
||
| @Extension | ||
| public class GlobalNodePropertiesConfigurator extends DataBoundConfigurator<EnvironmentVariablesNodeProperty> { |
There was a problem hiding this comment.
IMO this is the wrong fix and it is
thatField: ''regardless of where it is. If some config class neglects to call Util.fixEmpty (or fixEmptyAndTrim etc.) when processing a parameter to a @DataBoundSetter which cannot logically be the empty string, then fix that setter.
There was a problem hiding this comment.
that might have an huge impact on the export. Any single property with an empty String as value will be exported when nowadays is not
If some config class neglects to call Util.fixEmpty (or fixEmptyAndTrim etc.) when processing a parameter to a @DataBoundSetter which cannot logically be the empty string, then fix that setter.
which might mean to fix how many plugins? Although I agree with that being the 100% correct solution, that might be little realistic as users using the export nowadays will see unexpected changes in the export without a (from the user perspective) good reason
There was a problem hiding this comment.
which might mean to fix how many plugins?
Not sure, but they need to be fixed anyway even without JCasC.
Fixes: #2658
Exporting empty variables as an empty string seems not possible. There's a explicit check to avoid it and removing it would result in lots of empty configurations being exported, which is not desired.
Also, export works recursively, so any line being exported is not aware of the existence of any sibling, meaning in
keyandvaluelines are not aware of each other.Having these, this PR will allow reading a config file that contains variables without a value (as they are exported)
will be accepted, Jenkins will start normally and variable will be visible

Modified integration tests accordingly.
Your checklist for this pull request
🚨 Please review the guidelines for contributing to this repository.