Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign up[JENKINS-50164] Remove UI option to modify WS and builds locations #3364
Conversation
Test (almost) only: checking the previous behaviour is preserved, and the system property is accounted for when set.
Add necessary code to fix tests, and make the UI readonly.
| if (newBuildsDir != null && !buildsDir.equals(newBuildsDir)) { | ||
| LOGGER.log(Level.WARNING, "Changing builds directories from {0} to {1}. Beware that no automated data migration will occur.", | ||
| new String[]{buildsDir, newBuildsDir}); | ||
| buildsDir = newBuildsDir; |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| private static final String OLD_DEFAULT_WORKSPACES_DIR = "${ITEM_ROOTDIR}/" + WORKSPACE_DIRNAME; | ||
|
|
||
| /** | ||
| * Default value for the workspace's directories layout. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| * System property name to set {@link #buildsDir}. | ||
| * @see #getRawBuildsDir() | ||
| */ | ||
| public static final String BUILDS_DIR_PROP = Jenkins.class.getName() + ".BUILDS_DIR"; |
This comment has been minimized.
This comment has been minimized.
jglick
Mar 22, 2018
Member
I do not think these constants need to be public—we do not expect plugin Java code to refer to them.
This comment has been minimized.
This comment has been minimized.
| @@ -40,11 +40,11 @@ THE SOFTWARE. | |||
| ${it.rootDir} | |||
| </f:entry> | |||
| <f:advanced> | |||
| <f:entry field="rawWorkspaceDir" title="${%Workspace Root Directory}"> | |||
| <f:textbox/> | |||
| <f:entry field="rawWorkspaceDir" title="${%Workspace Root Directory}" > | |||
This comment has been minimized.
This comment has been minimized.
| </f:entry> | ||
| <f:entry field="rawBuildsDir" title="${%Build Record Root Directory}"> | ||
| <f:textbox/> | ||
| <f:textbox readonly="readonly"/> |
This comment has been minimized.
This comment has been minimized.
jglick
Mar 22, 2018
Member
Setting the readonly attribute will block a web browser from editing this field, but doConfigSubmit is continuing to accept modifications from HTTP posts! I think you want to delete those two lines as well.
I would really just suggest deleting this advanced block, and print a warning to the system log if there is an override which is not matched by the system property.
This comment has been minimized.
This comment has been minimized.
batmat
Mar 22, 2018
Author
Member
eeeek. Nice catch. I had deleted the associated lines in doConfigSubmit in #3360 but did a bad manipulation here and reverted this.
About the warning, I would like to avoid having it printed each time as WARNING, especially for instance since we'll use this in Essentials. Though I agree that logging as INFO when the value has not changed would serve the purpose I had here with keeping the UI to check the values.
This comment has been minimized.
This comment has been minimized.
| @Test | ||
| public void buildsDir() throws Exception { | ||
| loggerRule.record(Jenkins.class, Level.WARNING).capture(10); | ||
| story.addStep(new Statement() { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@jglick I believe I addressed all your comments. Only thing not done yet is checking how it works with https://issues.jenkins-ci.org/browse/JENKINS-21942 as requested in https://issues.jenkins-ci.org/browse/JENKINS-50164?focusedCommentId=332902&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-332902 |
|
Build succeeded, reviews are welcome. Thanks! |
|
I am sceptical about this - esp because of a JIRA I am currently trying to track down - and also as this should be managed as CaC and not a System property. Because as was said to me on a different PR No NOT another randomly hidden system property that alters behaviour / state. |
|
@jtnord What alternative to having a UI option (which clearly leads to broken behavior) do you propose? |
The UI option can lead to broken behaviour just as much as a System property. |
Not really, as it cannot easily be changed while Jenkins is running (and I'm trying to prevent CasC doing something dumb in this comment). Pulling the rug out from under builds in memory is pretty much unique to the UI option. (Also, no sane way around changing it via the UI, unless you really like XML). |
| } | ||
|
|
||
| if (mustSave) { | ||
| save(); |
This comment has been minimized.
This comment has been minimized.
jtnord
Mar 26, 2018
Member
seems scary as this is being called in a thread that is performing a load
This comment has been minimized.
This comment has been minimized.
batmat
Mar 27, 2018
Author
Member
Recommended by @jglick in #3364 (comment)
I'm not totally sure myself of the criticality of the risk, if there is one.
| * | ||
| * @since TODO | ||
| */ | ||
| public class JenkinsBuildsAndWorkspacesDirectoriesTest { |
This comment has been minimized.
This comment has been minimized.
jtnord
Mar 26, 2018
•
Member
Seems to be missing a test for the following:
- Custom build/workspace are set in existing Jenkins config (from version without this change)
- Jenkins is upgraded
- Jenkins config is saved
- configuration should not be reset - existing custom values should be retained until they set the system property
Because otherwise people are going to not do that step and mess things up.
And this implies there is no way to go back to default - once you have set the system property if you want to revert to the defaults you need to know what they are and set the system property to it (removing the system property should not change things)...
|
By broken I mean a user setting BUILD_ROOT=ITEM_ROOT. JENKINS-50335 |
| /*private*/ static void checkRawBuildsDir(String value) throws InvalidBuildsDir { | ||
|
|
||
| // do essentially what expandVariablesForDirectory does, without an Item | ||
| String replacedValue = expandVariablesForDirectory(value, |
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| /** | ||
| * @param value |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| public void badValueForBuildsDir() { | ||
| story.then((rule) -> { | ||
| final List<String> badValues = Arrays.asList( | ||
| "blah", |
This comment has been minimized.
This comment has been minimized.
jtnord
Apr 17, 2018
Member
so there are no bad values for windows?? this seems to be unix specific without an assume and may fail but likely not for the expected reason.
| @Test | ||
| public void fromPreviousCustomSetup() { | ||
|
|
||
| assumeFalse(Functions.isWindows()); // Default Windows lifecycle does not support restart. |
This comment has been minimized.
This comment has been minimized.
jtnord
Apr 17, 2018
Member
NIT: it is much nicer to use assumeFalse(" Default Windows lifecycle does not support restart.", Function.isWindows()) as then the reason for the skipped test will be reported.
This comment has been minimized.
This comment has been minimized.
|
Seems ok apart from the |
|
I fixed some of your comments @jtnord. Thanks for the review! To /all I plan to merge this before the next release, i.e. on Sunday max if nobody objects in the meantime. Thanks! |
|
Not sure I understand all the implications, but removing a UI option is generally a good thing, and I am assuming you are testing this. |
| <f:entry field="rawBuildsDir" title="${%Build Record Root Directory}"> | ||
| <f:textbox/> | ||
| </f:entry> | ||
| </f:advanced> |
This comment has been minimized.
This comment has been minimized.
jglick
Apr 20, 2018
Member
IMO: users should not be customizing this. If they do, they presumably have some reason and will be able to figure out example paths for themselves. If they are not customizing this, then they should have no reason to care. And the workspace root is only relevant for on-master builds, which you should never do to begin with.
| * So this test class uses a {@link RestartableJenkinsRule} to check the behaviour of this sysprop being | ||
| * present or not between two restarts. | ||
| * | ||
| * @since TODO |
This comment has been minimized.
This comment has been minimized.
| ); | ||
|
|
||
| story.then(steps -> { | ||
| assertTrue(story.j.getInstance().isDefaultBuildDir()); |
This comment has been minimized.
This comment has been minimized.
jglick
Apr 20, 2018
Member
The lambda takes a parameter. And getInstance is static. Conventionally
story.then(r -> {
assertTrue(r.jenkins.isDefaultBuildDir());|
On-holding this until the following is addressed (or at least gets a reasonable response):
|
|
Working on the on-holding reason now, hopefully to propose something very soon. To loop back with a discussion on IRC with Daniel, I'm generally against squashing. So please just do not squash this one if you merge it. Thanks! |
|
Just filed the docs PR linked above to un-on-hold this. Please review so that we can move forward here. Thanks! |
|
Going to merge this in the next 10 minutes if nobody objects. The PR was already approved, and I've fixed the reason for putting it On-Hold. |
Cf. jenkinsci/jenkins#3364 Manually tested for now, JENKINS-50940 will have the test automation for this.
|
Am i correctly understand: Or when empty Jenkins is running does it hit into wrong default by default? |
| "$JENKINS_HOME/foo/$ITEM_FULL_NAME", | ||
| "${ITEM_ROOTDIR}/builds"); | ||
|
|
||
| for (String goodValue : badValues) { |
This comment has been minimized.
This comment has been minimized.
|


batmat commentedMar 22, 2018
•
edited
Introduce system properties in lieu of the previous way using the UI for this.
Still leave the UI in readonly mode to ease checking configuration for admins.
Tests have been written to check using those system properties would work, even on an existing setup.
A warning log is now outputted when these system properties are used and changing the previous value, so that not only the help text warns about the fact there's no data migration.
See JENKINS-50164.
TODO before/just after merge:
* [x] document the new behavior, e.g. on the wiki or in the Jenkins handbook. This should be ready by the time the weekly changelog is published. Requested by @daniel-beck jenkins-infra/jenkins.io#1510Proposed changelog entries
Submitter checklist
* Use the
Internal:prefix if the change has no user-visible impact (API, test frameworks, etc.)Desired reviewers
@reviewbybees