暂不支持构建状态反馈
This commit is contained in:
parent
d0dc8da2c0
commit
d0eea86eb0
|
@ -1,147 +0,0 @@
|
|||
package com.gitee.jenkins.workflow;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.jenkinsci.plugins.workflow.steps.BodyExecution;
|
||||
import org.jenkinsci.plugins.workflow.steps.BodyExecutionCallback;
|
||||
import org.jenkinsci.plugins.workflow.steps.Step;
|
||||
import org.jenkinsci.plugins.workflow.steps.StepContext;
|
||||
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
|
||||
import org.jenkinsci.plugins.workflow.steps.StepExecution;
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
import org.kohsuke.stapler.DataBoundSetter;
|
||||
import org.kohsuke.stapler.export.ExportedBean;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import hudson.Extension;
|
||||
import hudson.model.Run;
|
||||
import hudson.model.TaskListener;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:robin.mueller@1und1.de">Robin Müller</a>
|
||||
*/
|
||||
@ExportedBean
|
||||
public class GiteeBuildsStep extends Step {
|
||||
|
||||
private List<String> builds;
|
||||
|
||||
@DataBoundConstructor
|
||||
public GiteeBuildsStep() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public StepExecution start(StepContext context) throws Exception {
|
||||
return new GiteeBuildStepExecution(context, this);
|
||||
}
|
||||
|
||||
@DataBoundSetter
|
||||
public void setBuilds(List<String> builds) {
|
||||
if (builds != null && builds.size() == 1) {
|
||||
this.builds = new ArrayList<>();
|
||||
for (String build : Splitter.on(",").omitEmptyStrings().trimResults().split(builds.get(0))) {
|
||||
this.builds.add(build);
|
||||
}
|
||||
} else {
|
||||
this.builds = builds;
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getBuilds() {
|
||||
return builds;
|
||||
}
|
||||
|
||||
public static class GiteeBuildStepExecution extends StepExecution {
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
private final transient Run<?, ?> run;
|
||||
|
||||
private final transient GiteeBuildsStep step;
|
||||
|
||||
private BodyExecution body;
|
||||
|
||||
GiteeBuildStepExecution(StepContext context, GiteeBuildsStep step) throws Exception {
|
||||
super(context);
|
||||
this.step = step;
|
||||
run = context.get(Run.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() throws Exception {
|
||||
body = getContext().newBodyInvoker()
|
||||
.withCallback(new BodyExecutionCallback() {
|
||||
@Override
|
||||
public void onStart(StepContext context) {
|
||||
run.addAction(new PendingBuildsAction(new ArrayList<>(step.builds)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(StepContext context, Object result) {
|
||||
PendingBuildsAction action = run.getAction(PendingBuildsAction.class);
|
||||
if (action != null && !action.getBuilds().isEmpty()) {
|
||||
TaskListener taskListener = getTaskListener(context);
|
||||
if (taskListener != null) {
|
||||
taskListener.getLogger().println("There are still pending Gitee builds. Please check your configuration");
|
||||
}
|
||||
}
|
||||
context.onSuccess(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(StepContext context, Throwable t) {
|
||||
context.onFailure(t);
|
||||
}
|
||||
})
|
||||
.start();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(@Nonnull Throwable cause) throws Exception {
|
||||
// should be no need to do anything special (but verify in JENKINS-26148)
|
||||
if (body != null) {
|
||||
body.cancel(cause);
|
||||
}
|
||||
}
|
||||
|
||||
private TaskListener getTaskListener(StepContext context) {
|
||||
if (!context.isReady()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return context.get(TaskListener.class);
|
||||
} catch (Exception x) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Extension
|
||||
public static final class DescriptorImpl extends StepDescriptor {
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Notify gitee about pending builds";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFunctionName() {
|
||||
return "giteeBuilds";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean takesImplicitBlockArgument() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Class<?>> getRequiredContext() {
|
||||
return ImmutableSet.of(TaskListener.class, Run.class);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,136 +0,0 @@
|
|||
package com.gitee.jenkins.workflow;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jenkinsci.plugins.workflow.steps.BodyExecution;
|
||||
import org.jenkinsci.plugins.workflow.steps.BodyExecutionCallback;
|
||||
import org.jenkinsci.plugins.workflow.steps.Step;
|
||||
import org.jenkinsci.plugins.workflow.steps.StepContext;
|
||||
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
|
||||
import org.jenkinsci.plugins.workflow.steps.StepExecution;
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
import org.kohsuke.stapler.DataBoundSetter;
|
||||
import org.kohsuke.stapler.export.ExportedBean;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import hudson.Extension;
|
||||
import hudson.model.Run;
|
||||
import hudson.model.TaskListener;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:robin.mueller@1und1.de">Robin Müller</a>
|
||||
*/
|
||||
@ExportedBean
|
||||
public class GiteeCommitStatusStep extends Step {
|
||||
|
||||
private String name;
|
||||
|
||||
@DataBoundConstructor
|
||||
public GiteeCommitStatusStep(String name) {
|
||||
this.name = StringUtils.isEmpty(name) ? null : name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StepExecution start(StepContext context) throws Exception {
|
||||
return new GiteeCommitStatusStepExecution(context, this);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@DataBoundSetter
|
||||
public void setName(String name) {
|
||||
this.name = StringUtils.isEmpty(name) ? null : name;
|
||||
}
|
||||
|
||||
public static class GiteeCommitStatusStepExecution extends StepExecution {
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
private final transient Run<?, ?> run;
|
||||
|
||||
private final transient GiteeCommitStatusStep step;
|
||||
|
||||
private BodyExecution body;
|
||||
|
||||
GiteeCommitStatusStepExecution(StepContext context, GiteeCommitStatusStep step) throws Exception {
|
||||
super(context);
|
||||
this.step = step;
|
||||
run = context.get(Run.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() throws Exception {
|
||||
final String name = StringUtils.isEmpty(step.name) ? "jenkins" : step.name;
|
||||
body = getContext().newBodyInvoker()
|
||||
.withCallback(new BodyExecutionCallback() {
|
||||
@Override
|
||||
public void onStart(StepContext context) {
|
||||
PendingBuildsAction action = run.getAction(PendingBuildsAction.class);
|
||||
if (action != null) {
|
||||
action.startBuild(name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(StepContext context, Object result) {
|
||||
context.onSuccess(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(StepContext context, Throwable t) {
|
||||
context.onFailure(t);
|
||||
}
|
||||
})
|
||||
.start();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(@Nonnull Throwable cause) throws Exception {
|
||||
// should be no need to do anything special (but verify in JENKINS-26148)
|
||||
if (body != null) {
|
||||
body.cancel(cause);
|
||||
}
|
||||
}
|
||||
|
||||
private TaskListener getTaskListener(StepContext context) {
|
||||
if (!context.isReady()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return context.get(TaskListener.class);
|
||||
} catch (Exception x) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Extension
|
||||
public static final class DescriptorImpl extends StepDescriptor {
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Update the commit status in Gitee depending on the build status";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFunctionName() {
|
||||
return "giteeCommitStatus";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean takesImplicitBlockArgument() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Class<?>> getRequiredContext() {
|
||||
return ImmutableSet.of(TaskListener.class, Run.class);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package com.gitee.jenkins.workflow;
|
||||
|
||||
|
||||
import hudson.model.Action;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
*/
|
||||
public class PendingBuildsAction implements Action, Serializable {
|
||||
|
||||
private final List<String> builds;
|
||||
|
||||
public PendingBuildsAction(List<String> builds) {
|
||||
this.builds = builds;
|
||||
}
|
||||
|
||||
public void startBuild(String name) {
|
||||
builds.remove(name);
|
||||
}
|
||||
|
||||
public List<String> getBuilds() {
|
||||
return builds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIconFileName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrlName() {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
package com.gitee.jenkins.workflow;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jenkinsci.plugins.workflow.steps.AbstractSynchronousStepExecution;
|
||||
import org.jenkinsci.plugins.workflow.steps.Step;
|
||||
import org.jenkinsci.plugins.workflow.steps.StepContext;
|
||||
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
|
||||
import org.jenkinsci.plugins.workflow.steps.StepExecution;
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
import org.kohsuke.stapler.DataBoundSetter;
|
||||
import org.kohsuke.stapler.export.ExportedBean;
|
||||
|
||||
import com.gitee.jenkins.gitee.api.model.BuildState;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import hudson.Extension;
|
||||
import hudson.model.Run;
|
||||
import hudson.model.TaskListener;
|
||||
import hudson.util.ListBoxModel;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:robin.mueller@1und1.de">Robin Müller</a>
|
||||
*/
|
||||
@ExportedBean
|
||||
public class UpdateGiteeCommitStatusStep extends Step {
|
||||
|
||||
private String name;
|
||||
private BuildState state;
|
||||
|
||||
@DataBoundConstructor
|
||||
public UpdateGiteeCommitStatusStep(String name, BuildState state) {
|
||||
this.name = StringUtils.isEmpty(name) ? null : name;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StepExecution start(StepContext context) throws Exception {
|
||||
return new UpdateGiteeCommitStatusStepExecution(context, this);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@DataBoundSetter
|
||||
public void setName(String name) {
|
||||
this.name = StringUtils.isEmpty(name) ? null : name;
|
||||
}
|
||||
|
||||
public BuildState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@DataBoundSetter
|
||||
public void setState(BuildState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public static class UpdateGiteeCommitStatusStepExecution extends AbstractSynchronousStepExecution<Void> {
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
private final transient Run<?, ?> run;
|
||||
|
||||
private final transient UpdateGiteeCommitStatusStep step;
|
||||
|
||||
UpdateGiteeCommitStatusStepExecution(StepContext context, UpdateGiteeCommitStatusStep step) throws Exception {
|
||||
super(context);
|
||||
this.step = step;
|
||||
run = context.get(Run.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void run() throws Exception {
|
||||
final String name = StringUtils.isEmpty(step.name) ? "jenkins" : step.name;
|
||||
PendingBuildsAction action = run.getAction(PendingBuildsAction.class);
|
||||
if (action != null) {
|
||||
action.startBuild(name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Extension
|
||||
public static final class DescriptorImpl extends StepDescriptor {
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Update the commit status in Gitee";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFunctionName() {
|
||||
return "updateGiteeCommitStatus";
|
||||
}
|
||||
|
||||
public ListBoxModel doFillStateItems() {
|
||||
ListBoxModel options = new ListBoxModel();
|
||||
for (BuildState buildState : EnumSet.allOf(BuildState.class)) {
|
||||
options.add(buildState.name());
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Class<?>> getRequiredContext() {
|
||||
return ImmutableSet.of(TaskListener.class, Run.class);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
<?jelly escape-by-default='true'?>
|
||||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
|
||||
<f:entry title="${%Build steps}" field="builds" description="${%Comma separated list of build steps}">
|
||||
<f:textbox/>
|
||||
</f:entry>
|
||||
</j:jelly>
|
|
@ -1,6 +0,0 @@
|
|||
<?jelly escape-by-default='true'?>
|
||||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
|
||||
<f:entry title="${%Build name}" field="name" help="/plugin/gitee/help/help-buildName.html">
|
||||
<f:textbox default="jenkins"/>
|
||||
</f:entry>
|
||||
</j:jelly>
|
|
@ -1,9 +0,0 @@
|
|||
<?jelly escape-by-default='true'?>
|
||||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
|
||||
<f:entry title="${%Build name}" field="name" help="/plugin/gitee/help/help-buildName.html">
|
||||
<f:textbox default="jenkins"/>
|
||||
</f:entry>
|
||||
<f:entry title="${%Build state}" field="state">
|
||||
<f:select/>
|
||||
</f:entry>
|
||||
</j:jelly>
|
Loading…
Reference in New Issue