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-50164] Remove UI option to modify WS and builds locations #3364

Merged
merged 17 commits into from Apr 24, 2018

Conversation

@batmat
Copy link
Member

batmat commented Mar 22, 2018

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#1510

Proposed changelog entries

  • JENKINS-50164: Removed the option to modify Build Record Root Directory and Workspace Root Directory from the User Interface directly. Those are now only modifiable using system properties, refer to the standard page for these values TODO: write docs there once/if merged. Remember that no data migration is handled when using those options on an existing setup.

Submitter checklist

  • JIRA issue is well described
  • Changelog entry appropriate for the audience affected by the change (users or developer, depending on the change). Examples
    * Use the Internal: prefix if the change has no user-visible impact (API, test frameworks, etc.)
  • Appropriate autotests or explanation to why this change has no tests
  • For dependency updates: links to external changelogs and, if possible, full diffs

Desired reviewers

@reviewbybees

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.
@batmat batmat requested a review from daniel-beck Mar 22, 2018
@batmat batmat changed the title WIP [JENKINS-50164] Remove UI option to modify WS and builds locations [JENKINS-50164] Remove UI option to modify WS and builds locations Mar 22, 2018
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.

Copy link
@jglick

jglick Mar 22, 2018

Member

And need to save(), I suspect.

This comment has been minimized.

Copy link
@batmat

batmat Mar 22, 2018

Author Member

done

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.

Copy link
@jglick

jglick Mar 22, 2018

Member

@see #workspaceDir

This comment has been minimized.

Copy link
@batmat

batmat Mar 22, 2018

Author Member

done, see below

* 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.

Copy link
@jglick

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.

Copy link
@batmat

batmat Mar 22, 2018

Author Member

fixed

@@ -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.

Copy link
@jglick

jglick Mar 22, 2018

Member

stray space

</f:entry>
<f:entry field="rawBuildsDir" title="${%Build Record Root Directory}">
<f:textbox/>
<f:textbox readonly="readonly"/>

This comment has been minimized.

Copy link
@jglick

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.

Copy link
@batmat

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.

Copy link
@batmat

batmat Mar 22, 2018

Author Member

done it all

@Test
public void buildsDir() throws Exception {
loggerRule.record(Jenkins.class, Level.WARNING).capture(10);
story.addStep(new Statement() {

This comment has been minimized.

Copy link
@jglick

jglick Mar 22, 2018

Member

Use then, which takes a SAM that can be implemented via lambda.

This comment has been minimized.

Copy link
@batmat

batmat Mar 22, 2018

Author Member

done

@batmat
Copy link
Member Author

batmat commented Mar 22, 2018

@batmat batmat requested a review from jglick Mar 22, 2018
@batmat
Copy link
Member Author

batmat commented Mar 23, 2018

Build succeeded, reviews are welcome. Thanks!

@jtnord
Copy link
Member

jtnord commented Mar 26, 2018

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.

@daniel-beck
Copy link
Member

daniel-beck commented Mar 26, 2018

@jtnord What alternative to having a UI option (which clearly leads to broken behavior) do you propose?

@jtnord
Copy link
Member

jtnord commented Mar 26, 2018

@daniel-beck

also as this should be managed as CaC and not a System property.

The UI option can lead to broken behaviour just as much as a System property.
At least in the UI you can do FormValidation such that they can be warned before they submit...

@daniel-beck
Copy link
Member

daniel-beck commented Mar 26, 2018

@jtnord

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.

Copy link
@jtnord

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.

Copy link
@batmat

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.

Copy link
@jtnord

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)...

@daniel-beck
Copy link
Member

daniel-beck commented Mar 26, 2018

It is unclear why #3360 was closed instead of updated, but given @jtnord's comments it seems quite a few of the review comments there are still relevant here.

@jtnord
Copy link
Member

jtnord commented Mar 26, 2018

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.

Copy link
@jtnord

jtnord Apr 17, 2018

Member

this method is utterly confusing

}

/**
* @param value

This comment has been minimized.

Copy link
@jtnord

jtnord Apr 17, 2018

Member

useless javadoc. what is it checking for - embedding bitcoins?

This comment has been minimized.

Copy link
@batmat

batmat Apr 20, 2018

Author Member

Fixed

public void badValueForBuildsDir() {
story.then((rule) -> {
final List<String> badValues = Arrays.asList(
"blah",

This comment has been minimized.

Copy link
@jtnord

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.

Copy link
@jtnord

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.

Copy link
@batmat

batmat Apr 20, 2018

Author Member

Fixed

Copy link
Member

jtnord left a comment

Seems ok apart from the checkRawBuildsDir method which is thoroughly confusing to me.

@batmat
Copy link
Member Author

batmat commented Apr 20, 2018

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!

@jglick
jglick approved these changes Apr 20, 2018
Copy link
Member

jglick left a comment

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.

Copy link
@jglick

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.

Copy link
@jglick

jglick Apr 20, 2018

Member

No @since tag needed on a test.

);

story.then(steps -> {
assertTrue(story.j.getInstance().isDefaultBuildDir());

This comment has been minimized.

Copy link
@jglick

jglick Apr 20, 2018

Member

The lambda takes a parameter. And getInstance is static. Conventionally

story.then(r -> {
    assertTrue(r.jenkins.isDefaultBuildDir());
@daniel-beck daniel-beck added the on-hold label Apr 21, 2018
@daniel-beck
Copy link
Member

daniel-beck commented Apr 21, 2018

On-holding this until the following is addressed (or at least gets a reasonable response):

Since we're removing documentation from Jenkins, make sure to 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.

Also, make sure the PR comment and changelog message are updated.

@batmat
Copy link
Member Author

batmat commented Apr 22, 2018

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!

@batmat
Copy link
Member Author

batmat commented Apr 23, 2018

Just filed the docs PR linked above to un-on-hold this. Please review so that we can move forward here.

Thanks!

@batmat batmat removed the on-hold label Apr 24, 2018
@batmat
Copy link
Member Author

batmat commented Apr 24, 2018

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.

@batmat
Copy link
Member Author

batmat commented Apr 24, 2018

For the record, the PR was built green previously. The current failure seems like an infra issue.

image

image

@batmat batmat merged commit a363f2e into jenkinsci:master Apr 24, 2018
1 check failed
1 check failed
continuous-integration/jenkins/pr-merge This commit cannot be built
Details
@batmat batmat deleted the batmat:JENKINS-50164 branch Apr 24, 2018
batmat added a commit to batmat/evergreen that referenced this pull request Apr 27, 2018
batmat added a commit to batmat/evergreen that referenced this pull request Apr 27, 2018
Cf. jenkinsci/jenkins#3364

Manually tested for now,
JENKINS-50940 will have the test automation for this.
@KostyaSha
Copy link
Member

KostyaSha commented Oct 8, 2019

Am i correctly understand:
1 Jenkins.java: private static final String DEFAULT_BUILDS_DIR = "${ITEM_ROOTDIR}/builds"; is a default value
2 Then JenkinsRule calls Jenkins.loadTasks() -> Jenkins.loadConfig();,
3 by default config.xml is missing in tests, so checkRawBuildsDir(buildsDir) gets checkRawBuildsDir("${ITEM_ROOTDIR}/builds")
4. which expands to .cut../jobs/doCheckRawBuildsDir-Marker$foo/builds and fails because it's not an absolute path?

Or when empty Jenkins is running does it hit into wrong default by default?

@KostyaSha
Copy link
Member

KostyaSha commented Oct 8, 2019

"$JENKINS_HOME/foo/$ITEM_FULL_NAME",
"${ITEM_ROOTDIR}/builds");

for (String goodValue : badValues) {

This comment has been minimized.

Copy link
@KostyaSha

KostyaSha Oct 8, 2019

Member

so is it good or bad value/values?

@jglick
Copy link
Member

jglick commented Oct 8, 2019

when empty Jenkins is running does it hit into wrong default

JENKINS-21942

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

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.