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-39203] Create new action to mark a FlowNode with a result such as unstable #91

Merged
merged 8 commits into from
May 10, 2019

Conversation

dwnusbaum
Copy link
Member

@dwnusbaum dwnusbaum commented Apr 18, 2019

See JENKINS-39203. (I am intentionally not updating the status of that ticket or assigning it to myself until I am ready to merge/release all relevant changes to avoid giving users premature hope of a fix and so that I have clear answers for what will and won't work and when any fixes will be released.) Subsumes #63.

This PR adds a new action named WarningAction. This action can be stored on a FlowNode to mark that although it completed successfully, some kind of non-fatal problem occurred. For now, this action will be used by Blue Ocean to mark stages containing a FlowNode with a WarningAction as Result.UNSTABLE.

In the future, if we wanted to add the ability to track some new kind of non-fatal result, we could update WarningAction to store a custom Result (or similar) and use that in visualizations to modify how the action should be displayed.

Upstream PRs:

@dwnusbaum
Copy link
Member Author

Closing and reopening in an attempt to get a CI build.

@dwnusbaum dwnusbaum closed this Apr 18, 2019
@dwnusbaum dwnusbaum reopened this Apr 18, 2019
@dwnusbaum dwnusbaum closed this Apr 18, 2019
@dwnusbaum dwnusbaum reopened this Apr 18, 2019
@dwnusbaum dwnusbaum closed this Apr 18, 2019
@dwnusbaum dwnusbaum reopened this Apr 18, 2019
@dwnusbaum
Copy link
Member Author

I think I'm running into JENKINS-54126, so I'll just deploy snapshots manually.

public final class WarningAction implements PersistentAction {
private final @Nonnull String message;

public WarningAction(@Nonnull String message) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe it would make more sense for this to be @Nullable so that something like unstable() with no message would work without having to create some kind of default message.

Copy link
Member

Choose a reason for hiding this comment

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

I do not see a use case for a null message, so would suggest keeping it @Nonnull unless and until one is found.

Copy link
Member

Choose a reason for hiding this comment

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

On second thought, perhaps it would be appropriate to have the constructor take no arguments, then use the idiom

public WarningAction withMessage(@Nonnull String message) {
    this.message = message;
    return this;
}

as I think it is likely we will at some point want an associated URL and perhaps even a badge icon.

Copy link
Member Author

Choose a reason for hiding this comment

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

Any particular reason to prefer withMessage, withUrl, etc. over adding new constructors that take additional arguments? With the former pattern it is easy to forget to call withMessage. We could use the builder pattern and validate that the message is non-null when constructing the WarningAction from the builder, but that seems like overkill.

Copy link
Member

Choose a reason for hiding this comment

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

The builder style makes it easier to introduce new features compatibly. If we decide that a message is mandatory, then keep it in the constructor.

@dwnusbaum dwnusbaum marked this pull request as ready for review April 22, 2019 18:39
Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

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

Sounds fine in isolation.

import javax.annotation.Nonnull;
import jenkins.model.Jenkins;
import org.apache.commons.io.output.NullOutputStream;

/**
* Attached to {@link AtomNode} that caused an error.
* Attached to {@link FlowNode} that caused an error.
Copy link
Member

Choose a reason for hiding this comment

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

Good catch!

public final class WarningAction implements PersistentAction {
private final @Nonnull String message;

public WarningAction(@Nonnull String message) {
Copy link
Member

Choose a reason for hiding this comment

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

I do not see a use case for a null message, so would suggest keeping it @Nonnull unless and until one is found.

c = BallColor.ABORTED;
} else {
c = BallColor.RED;
}
} else if (getPersistentAction(WarningAction.class) != null) {
c = BallColor.YELLOW;
Copy link
Member Author

Choose a reason for hiding this comment

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

Here is an example of what this change looks like for the following pipeline:

stage('unstable-one') {
    unstable('foobar')
}
stage('success') {
    echo('whatever')
}
stage('failure') {
    unstable('three')
    error('uncaught')
}

Screen Shot 2019-04-23 at 12 24 36

For now only the actual FlowNode that has the WarningAction attached will be shown as unstable (unlike Blue Ocean in jenkinsci/pipeline-graph-analysis-plugin#25 which searches all FlowNodes in a stage/branch for a WarningAction.). This seems like the most obvious behavior to me, but I could make it work like Blue Ocean if desired.

@dwnusbaum dwnusbaum changed the title [JENKINS-39203] Create new action to mark a FlowNode as unstable [JENKINS-39203] Create new action to mark a FlowNode with a result such as unstable Apr 30, 2019
@dwnusbaum dwnusbaum requested a review from jglick May 9, 2019 17:07
@dwnusbaum
Copy link
Member Author

dwnusbaum commented May 10, 2019

All of the upstream PRs are using the current version of the API and I don't anticipate any further changes to it right now, so I'm going to go ahead and merge this PR and release the plugin.

@dwnusbaum dwnusbaum merged commit a7141f0 into jenkinsci:master May 10, 2019
@dwnusbaum dwnusbaum deleted the JENKINS-39203 branch May 10, 2019 20:58
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.

4 participants