Skip to content

upgrade workflow-api to list (un)stashed files#133

Closed
joseblas wants to merge 2 commits intojenkinsci:masterfrom
joseblas:improve-stash-step
Closed

upgrade workflow-api to list (un)stashed files#133
joseblas wants to merge 2 commits intojenkinsci:masterfrom
joseblas:improve-stash-step

Conversation

@joseblas
Copy link
Copy Markdown

No description provided.

Comment thread pom.xml
<revision>2.23</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.249.1</jenkins.version>
<jenkins.version>2.264-SNAPSHOT</jenkins.version>
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.

Use 2.263, and please file a separate PR for removing reflection, so that is not all mixed in here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ok about removing reflection, but some changes will needed in Jenkins-core (jenkinsci/jenkins#5023 (review)) so a new version will be needed.

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.

Preparing this in #134.

private @CheckForNull
String includes;
private @CheckForNull
String excludes;
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.

Please avoid gratuitous whitespace changes.

String gibberish = file.getCanonicalPath().split("/" + name + "/")[0];
logger.println("stashed file " + StringUtils.substring(file.getCanonicalPath(), gibberish.length()));
} catch (IOException | InterruptedException e) {
logger.println("stashed file " + file.getName());
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.

This will be an NPE.

}

@DataBoundSetter
public void setVerbose(boolean verbose) {
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.

Does this really need to be an explicit option? If printing messages is useful, just do it by default, and maybe truncate display after ten or twenty lines so you do not get too spammy.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

happy to discuss it

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

indeed, this is a good example why printing should be done in here, if the list is truncated or not is responsibility of this plugin, not workflow-api which has to supply that list only.

Copy link
Copy Markdown
Member

@jglick jglick Oct 23, 2020

Choose a reason for hiding this comment

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

If you just get rid of the step option and print some reasonable level of detail by default then you need no API change and no patch to this plugin (other than perhaps an integration test).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'd rather do the right thing, which is (to me)to pass the files (un)stashed back to the step to print it if appropriate.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The verbose parameter needs to be optional as the task describes, and by default should be false to ensure that the behavior is consistent with the previous releases. So, this does not need to be trunked.

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.

Why do we care if the behavior is identical to previous releases? This is just diagnostic logging as a convenience.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

for is more about responsibilities, and for me there is no need to log as a convenience. The log has to be printed in the StashStep if verbose. And StashManager to provide a list a changes.

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.

At least pass the verbose flag into the StashManager methods and let the implementation handle the printing.

Comment thread pom.xml
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.23</version>
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.

Need to retain TODO comments indicating that this should be removed once in the BOM

Comment thread pom.xml
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>2.41-SNAPSHOT</version>
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.

Comment thread pom.xml
<artifactId>scm-api</artifactId>
<version>2.6.4</version>
<scope>test</scope>
</dependency>
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.

Very likely not what you wanted to do. If you ran into a RequireUpperBoundsDeps error because you went outside the BOM, add to dependencyManagement (not dependencies) and mark with a TODO comment to remove as soon as possible.

r.assertLogContains("stashed file /p/p/p/other", b);
r.assertLogContains("unstashed file /p/elsewhere/fname", b);
r.assertLogContains("unstashed file /p/elsewhere/other", b);
assertEquals("{}", StashManager.stashesOf(b).toString()); // TODO flake expected:<{[]}> but was:<{[from-top={elsewhere/fname=whatever}, whatever={fname=whatever, other=more}]}>
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.

Copy-paste?

String name = getContext().get(Run.class).getParent().getName();
logger = getContext().get(TaskListener.class).getLogger();
String gibberish = file.getCanonicalPath().split("/" + name + "/")[0];
logger.println("stashed file " + StringUtils.substring(file.getCanonicalPath(), gibberish.length()));
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.

Why the absolute paths? Everything should be using relative paths here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

how?


@Override
protected Void run() throws Exception {
List<File> stash = StashManager.stash(getContext().get(Run.class), step.name, getContext().get(FilePath.class), getContext().get(Launcher.class), getContext().get(EnvVars.class), getContext().get(TaskListener.class), step.includes, step.excludes,
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.

File? Does not smell right. That could only refer to paths on the controller, and stashes are archived into a tarball. If these “files” are on an agent, then you cannot use File to refer to them. You could use FilePath but (as above) you probably just meant to use String (relative paths).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

my goal is to pass something neutral, like a file (or FilePAth), or even a String. I did passed a File in order to provide more info in higher levels, not meaning to pass the actual file. Indeed, something like a DTO, which could be created.

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.

Just String should suffice. stash and unstash deal with paths relative to the contextual working dir, so the absolute file path is not really interesting.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would say an URI :)

@jglick
Copy link
Copy Markdown
Member

jglick commented Oct 23, 2020

See #54.

@jglick
Copy link
Copy Markdown
Member

jglick commented Jan 6, 2022

Obsolete I guess?

@jglick jglick closed this Jan 6, 2022
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.

3 participants