Skip to content

Commit

Permalink
[JENKINS-30465] Post Build step unable to change status of build
Browse files Browse the repository at this point in the history
We've changed our post build step to a Recorder, one which is able to change the result.

This also means we had to remove the automatically added git publisher. This now needs to
be added manually.
  • Loading branch information
MadsNielsen authored and Thierry Lacour committed Oct 30, 2015
1 parent 571778d commit 019c19b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 66 deletions.
Expand Up @@ -5,7 +5,6 @@
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.Describable;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import hudson.tasks.BuildWrapper;
Expand All @@ -14,7 +13,6 @@
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.pretestedintegration.exceptions.EstablishWorkspaceException;
import org.jenkinsci.plugins.pretestedintegration.exceptions.IntegrationFailedException;
import org.jenkinsci.plugins.pretestedintegration.exceptions.NothingToDoException;
Expand All @@ -37,7 +35,7 @@ public PretestedIntegrationBuildWrapper(final AbstractSCMBridge scmBridge) {
}

/**
* Jenkins hook that fires after the workspace is initialized. Calls the
* Jenkins hook that fires after the workspace is initialised. Calls the
* SCM-specific function according to the chosen SCM.
*
* @param build
Expand All @@ -53,11 +51,6 @@ public BuildWrapper.Environment setUp(AbstractBuild build, Launcher launcher, Bu
scmBridge.isApplicable(build, listener);
scmBridge.ensureBranch(build, launcher, listener, scmBridge.getExpandedBranch(build.getEnvironment(listener)));
scmBridge.prepareWorkspace(build, launcher, listener);
try {
ensurePublisher(build);
} catch (IOException ex) {
LOGGER.log(Level.WARNING, LOG_PREFIX + " " + "Failed to add publisher", ex);
}
} catch (NothingToDoException e) {
build.setResult(Result.NOT_BUILT);
listener.getLogger().println(e.getMessage());
Expand All @@ -80,14 +73,6 @@ public BuildWrapper.Environment setUp(AbstractBuild build, Launcher launcher, Bu
return proceedToBuildStep ? environment : null;
}

public void ensurePublisher(AbstractBuild<?, ?> build) throws IOException {
Describable<?> describable = build.getProject().getPublishersList().get(PretestedIntegrationPostCheckout.class);
if (describable == null) {
LOGGER.info("Adding publisher to project");
build.getProject().getPublishersList().add(new PretestedIntegrationPostCheckout());
}
}

/**
* Prints out version information.
*
Expand Down
Expand Up @@ -4,11 +4,13 @@
import hudson.Extension;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.Descriptor;
import hudson.model.FreeStyleProject;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
import hudson.tasks.Recorder;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -19,23 +21,12 @@
* The publisher determines what will happen when the build has been run.
* Depending on the chosen SCM, a more specific function will be called.
*/
public class PretestedIntegrationPostCheckout extends Publisher {
public class PretestedIntegrationPostCheckout extends Recorder {

@DataBoundConstructor
public PretestedIntegrationPostCheckout() {
}

/**
* This should ensure that we only run, when the build result can no longer
* be changes (is final).
*
* @return
*/
@Override
public boolean needsToRunAfterFinalized() {
return true;
}

private AbstractSCMBridge getScmBridge(AbstractBuild<?, ?> build) throws AbortException {
if (build.getProject() instanceof FreeStyleProject) {
FreeStyleProject p = (FreeStyleProject) build.getProject();
Expand Down Expand Up @@ -80,12 +71,17 @@ public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.BUILD;
}

@Extension
public static final class DescriptorImpl extends Descriptor<Publisher> {
@Extension(ordinal = Integer.MIN_VALUE)
public static final class DescriptorImpl extends BuildStepDescriptor<Publisher> {

@Override
public String getDisplayName() {
return "Pretested Integration post-build";
return "Pretested Integration Publisher";
}

@Override
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
return true;
}
}

Expand Down
Expand Up @@ -45,7 +45,6 @@
import org.kohsuke.stapler.DataBoundConstructor;

public class GitBridge extends AbstractSCMBridge {
private static final int unlikelyExitCode = -999; // An very unlikely exit code, that we use as default
private static final Logger LOGGER = Logger.getLogger(GitBridge.class.getName());

private String revisionId;
Expand Down
Expand Up @@ -12,22 +12,14 @@
import org.jenkinsci.plugins.gitclient.Git;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.gitclient.MergeCommand;
import org.jenkinsci.plugins.pretestedintegration.AbstractSCMBridge;
import org.jenkinsci.plugins.pretestedintegration.IntegrationStrategy;
import org.jenkinsci.plugins.pretestedintegration.PretestedIntegrationBuildWrapper;
import org.jenkinsci.plugins.pretestedintegration.exceptions.IntegrationFailedException;
import org.jenkinsci.plugins.pretestedintegration.exceptions.NothingToDoException;
import org.jenkinsci.plugins.pretestedintegration.exceptions.UnsupportedConfigurationException;

public class GitIntegrationStrategy extends IntegrationStrategy {
public abstract class GitIntegrationStrategy extends IntegrationStrategy {

private static final Logger logger = Logger.getLogger(GitIntegrationStrategy.class.getName());

@Override
public void integrate(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, AbstractSCMBridge bridge) throws IntegrationFailedException, NothingToDoException, UnsupportedConfigurationException {
throw new UnsupportedOperationException("Implement in subclasses");
}

/**
* Creates a PersonIdent object from a full Git identity string.
* @param identity The Git identity string to parse. ex.: john Doe <Joh@praqma.net> 1442321765 +0200
Expand Down

This file was deleted.

0 comments on commit 019c19b

Please sign in to comment.