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

Add withChecks step #49

Merged
merged 11 commits into from
Dec 20, 2020
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,20 @@ If enabled, the statuses will be published in different stages of a Jenkins buil

### Pipeline Usage

Instead of depending on consumers plugins, the users can publish their checks directly in the pipeline script:
- publishChecks: you can publish checks directly in the pipeline script instead of depending on consumer plugins:

```
publishChecks name: 'example', title: 'Pipeline Check', summary: 'check through pipeline', text: 'you can publish checks in pipeline script', detailsURL: 'https://github.com/jenkinsci/checks-api-plugin#pipeline-usage'
```

- withChecks: you can inject the check's name into the closure for other steps to use:
XiongKezhi marked this conversation as resolved.
Show resolved Hide resolved

```
withChecks(name: 'injected name') {
// some other steps that will extract the name
}
```

timja marked this conversation as resolved.
Show resolved Hide resolved
## Guides

- [Consumers Guide](docs/consumers-guide.md)
Expand Down
13 changes: 1 addition & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

<properties>
<java.level>8</java.level>
<revision>1.1.1</revision>
<changelist>-SNAPSHOT</changelist>
<revision>1.2.0</revision>
Copy link
Member

Choose a reason for hiding this comment

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

It still should be a SNAPSHOT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The sem-ver plugin will warn about compatibility if add SNAPSHOT


<!-- Jenkins Plug-in Dependencies Versions -->
<plugin-util-api.version>1.4.0</plugin-util-api.version>
Expand Down Expand Up @@ -114,16 +113,6 @@
<old>class io.jenkins.plugins.checks.BuildStatusChecksPublisher</old>
<justification>BuildStatusChecksPublisher has no consumers, should be safe to move.</justification>
</item>
<item>
<code>java.class.added</code>
<new>class io.jenkins.plugins.checks.steps.ChecksInfo</new>
<justification>Adding a new step wil not break back compatibility</justification>
</item>
<item>
<code>java.class.added</code>
<new>class io.jenkins.plugins.checks.steps.WithChecksStep</new>
<justification>Adding a new step wil not break back compatibility</justification>
</item>
</revapi.ignore>
</analysisConfiguration>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.jenkins.plugins.checks.steps;

import edu.hm.hafner.util.VisibleForTesting;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.model.Run;
import hudson.model.TaskListener;
import org.jenkinsci.plugins.workflow.steps.*;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

import java.io.Serializable;
import java.util.*;
Expand All @@ -16,7 +18,7 @@
public class WithChecksStep extends Step implements Serializable {
private static final long serialVersionUID = 1L;

private final String name;
private String name;

/**
* Creates the step with a name to inject.
Expand All @@ -31,6 +33,15 @@ public WithChecksStep(final String name) {
this.name = name;
}

@DataBoundSetter
public void setName(final String name) {
this.name = name;
}

XiongKezhi marked this conversation as resolved.
Show resolved Hide resolved
public String getName() {
return name;
}

@Override
public StepExecution start(final StepContext stepContext) {
return new WithChecksStepExecution(stepContext, this);
Expand All @@ -55,6 +66,12 @@ public Set<? extends Class<?>> getRequiredContext() {
public boolean takesImplicitBlockArgument() {
return true;
}

@NonNull
@Override
public String getDisplayName() {
return "Inject checks properties into its closure";
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:f="/lib/form">

<f:entry title="${%title.name}" field="name">
<f:textbox />
</f:entry>

</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
title.name=Name