Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,17 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import jenkins.model.Jenkins;
import org.jenkinsci.plugins.pretestedintegration.exceptions.*;

/**
* Abstract class representing an SCM bridge.
*/
public abstract class AbstractSCMBridge implements Describable<AbstractSCMBridge>, ExtensionPoint {
private static final Logger LOGGER = Logger.getLogger(AbstractSCMBridge.class.getName());


/**
* Information about the result of the integration (Unknown, Conflict, Build, Push).
*/
protected String resultInfo = "Unknown";
protected abstract String getIntegrationBranch();

/**
Expand Down Expand Up @@ -216,20 +211,6 @@ public static List<SCMBridgeDescriptor<?>> getDescriptors() {
return descriptors;
}

/**
* @return The information of the result of the Phlow
*/
public String getResultInfo() {
return resultInfo;
}

/**
* @param resultInfo
*/
public void setResultInfo(String resultInfo) {
this.resultInfo = resultInfo;
}

/**
* @param environment environment
* @return The Integration Branch name as variable expanded if possible - otherwise return integrationBranch
Expand All @@ -238,7 +219,6 @@ public String getExpandedIntegrationBranch(EnvVars environment) {
return environment.expand(getIntegrationBranch());
}


/**
* @param environment The environment to expand the integrationBranch in
* @return The Integration Branch name, expanded using given EnvVars.
Expand All @@ -250,4 +230,8 @@ public String getExpandedIntegrationBranch(EnvVars environment) {
public Result getRequiredResult() {
return Result.SUCCESS;
}

void setIntegrationFailedStatusUnstable(boolean integrationFailedStatusUnstable) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
import org.jenkinsci.plugins.pretestedintegration.exceptions.IntegrationFailedException;
import org.jenkinsci.plugins.pretestedintegration.exceptions.NothingToDoException;
import org.jenkinsci.plugins.pretestedintegration.exceptions.UnsupportedConfigurationException;
import org.jenkinsci.plugins.pretestedintegration.scm.git.GitBridge;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

/**
* The build wrapper determines what will happen before the build will run.
Expand All @@ -40,36 +38,19 @@ public class PretestedIntegrationBuildWrapper extends BuildWrapper {
/**
* The SCM Bridge used for this project.
*/
public final GitBridge scmBridge;

public final AbstractSCMBridge scmBridge;
/**
* Constructor for the Build Wrapper.
* DataBound to work with Jenkins UI.
* @param scmBridge the SCM bridge
* @param integrationFailedStatusUnstable
* @param allowedNoCommits
*/
@DataBoundConstructor
public PretestedIntegrationBuildWrapper(final GitBridge scmBridge) {
public PretestedIntegrationBuildWrapper(final AbstractSCMBridge scmBridge) {
this.scmBridge = scmBridge;
}
@DataBoundSetter
public void setIntegrationFailedStatusUnstable(boolean integrationFailedStatusUnstable){
this.scmBridge.setIntegrationFailedStatusUnstable(integrationFailedStatusUnstable);
}

public boolean getIntegrationFailedStatusUnstable(){
if ( scmBridge == null ) {
return false;
} else {
return scmBridge.getIntegrationFailedStatusUnstable();
}
}
public String getAllowedNoCommits(){
if ( scmBridge == null ) {
return "";
} else {
return Integer.toString(scmBridge.getAllowedNoCommits());
}
}
public String getIntegrationBranch(){
if ( scmBridge == null ) {
return "master";
Expand Down Expand Up @@ -143,14 +124,6 @@ public String getVersion(){
*/
@Extension
public static class DescriptorImpl extends BuildWrapperDescriptor {

/**
* Constructor for the Descriptor
*/
public DescriptorImpl() {
load();
}

/**
* {@inheritDoc}
*/
Expand All @@ -171,11 +144,13 @@ public List<SCMBridgeDescriptor<?>> getSCMBridges() {
*/
@Override
public boolean isApplicable(AbstractProject<?, ?> arg0) {
if (arg0 instanceof FreeStyleProject)
if (arg0 instanceof FreeStyleProject) {
return true;
if (arg0 instanceof MatrixProject)
} else if (arg0 instanceof MatrixProject) {
return true;
return false;
} else {
return false;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public Object pretestedIntegration(String strategy, String branch, String reposi
break;
}

GitBridge bridge = new GitBridge(integrationStrategy, branch, repository, Integer.getInteger(allowedNoCommits));
return new PretestedIntegrationBuildWrapper(new GitBridge(integrationStrategy, branch, repository, Integer.getInteger(allowedNoCommits)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private AbstractSCMBridge getScmBridge(AbstractBuild<?, ?> build, BuildListener
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
AbstractProject<?, ?> proj = build.getProject();
GitSCM client = (GitSCM)build.getProject().getScm();
if ( ! (client instanceof GitSCM) || client == null ) {
if ( ! (client instanceof GitSCM) ) {
listener.getLogger().println(PretestedIntegrationBuildWrapper.LOG_PREFIX + "Unsupported SCM type: expects Git");
return false;
}
Expand All @@ -116,27 +116,23 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
} catch (NullPointerException | IllegalArgumentException e) {
listener.getLogger().println(String.format("Caught %s during post-checkout. Failing build.", e.getClass().getSimpleName()));
e.printStackTrace(listener.getLogger());
bridge.setResultInfo("Unknown");
bridge.updateBuildDescription((Run)build);
throw new AbortException("Unexpected error. Trace written to log.");
} catch (IOException e) {
//All our known errors are IOExceptions. Just print the message, log the error.
listener.getLogger().println(e.getMessage());
LOGGER.log(Level.SEVERE, "IOException in post checkout", e);
bridge.setResultInfo("Unknown");
bridge.updateBuildDescription(build, launcher, listener);
throw new AbortException(e.getMessage());
}
}
if ( build.getResult() == Result.SUCCESS ) {
bridge.setResultInfo("Ok");
}
bridge.updateBuildDescription((Run)build);
return true;
} else { /* */
if (proj instanceof MatrixConfiguration) {
listener.getLogger().println(PretestedIntegrationBuildWrapper.LOG_PREFIX + "MatrixConfiguration/sub - skipping publisher - leaving it to root job");
bridge.setResultInfo("Ok");
bridge.updateBuildDescription(build, launcher, listener);
} else {
listener.getLogger().println(PretestedIntegrationBuildWrapper.LOG_PREFIX + "Performing pre-verified post build steps");
Expand All @@ -153,7 +149,6 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
throw new AbortException(e.getMessage());
}
}
bridge.setResultInfo("Ok");
bridge.updateBuildDescription(build, launcher, listener);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.jenkinsci.plugins.pretestedintegration.PretestedIntegrationBuildWrapper;
import org.jenkinsci.plugins.pretestedintegration.SCMBridgeDescriptor;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

/**
* The Git SCM Bridge.
Expand Down Expand Up @@ -67,15 +68,15 @@ public class GitBridge extends AbstractSCMBridge {
* Constructor for GitBridge.
* DataBound for use in the UI.
* @param integrationStrategy The selected IntegrationStrategy
* @param branch The Integration Branch name
* @param repositoryName The Integration Repository name
* @param integrationBranch The Integration Branch name
* @param repoName The Integration Repository name
* @param allowedNoCommits The Integration Repository name
*/
@DataBoundConstructor
public GitBridge(IntegrationStrategy integrationStrategy, final String branch, final String repositoryName, final Integer allowedNoCommits) {
public GitBridge(IntegrationStrategy integrationStrategy, String integrationBranch, String repoName, final Integer allowedNoCommits) {
super(integrationStrategy);
this.integrationBranch = branch;
this.repoName = repositoryName;
this.integrationBranch = integrationBranch;
this.repoName = repoName;
this.allowedNoCommits = allowedNoCommits;
}

Expand Down Expand Up @@ -271,7 +272,7 @@ public void updateBuildDescription(Run<?, ?> run) throws IOException {
*/
@Override
public String createBuildDescription(String triggerBranchName) throws NothingToDoException, UnsupportedConfigurationException, IOException, InterruptedException {
return String.format("%s", "(" + getResultInfo() + "):" + triggerBranchName + " -> " + integrationBranch);
return String.format("%s", "(" + "REPLACEDME" + "):" + triggerBranchName + " -> " + integrationBranch);
}


Expand Down Expand Up @@ -360,9 +361,7 @@ public void handlePostBuild(AbstractBuild<?, ?> build, Launcher launcher, BuildL

Result result = build.getResult();
if (result != null && result.isBetterOrEqualTo(getRequiredResult())) {
setResultInfo("Push");
pushToIntegrationBranch(build, listener);
setResultInfo("CleanUpRemote");
deleteIntegratedBranch(build, launcher, listener);
} else {
LOGGER.log(Level.WARNING, "Build result not satisfied - skipped post-build step.");
Expand Down Expand Up @@ -411,6 +410,7 @@ public boolean getIntegrationFailedStatusUnstable() {
return this.integrationFailedStatusUnstable;
}

@DataBoundSetter
public void setIntegrationFailedStatusUnstable( boolean integrationFailedStatusUnstable) {
this.integrationFailedStatusUnstable = integrationFailedStatusUnstable;
}
Expand All @@ -419,13 +419,15 @@ public Integer getAllowedNoCommits() {
return this.allowedNoCommits;
}

public void setAllowedNoCommits( Integer allowedNoCommits) {
@DataBoundSetter
public void setAllowedNoCommits(int allowedNoCommits) {
this.allowedNoCommits = allowedNoCommits;
}

/**
* @param repositoryName the repositoryName to set
*/
@DataBoundSetter
public void setRepoName(String repositoryName) {
this.repoName = repositoryName;
}
Expand All @@ -444,13 +446,6 @@ public String getExpandedRepository(EnvVars environment) {
@Extension
public static final class DescriptorImpl extends SCMBridgeDescriptor<GitBridge> {

/**
* Constructor for the Descriptor
*/
public DescriptorImpl() {
load();
}

/**
* {@inheritDoc }
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ protected boolean tryRebase(ObjectId commitId, GitClient client, String branch )
* @param commitId The commit
* @param logger The logger for console logging
* @param client The GitClient
* @param commitCount
* @return true if the FF merge was a success, false if the integrationBranch isn't
* suitable for a FF merge.
* @throws IntegrationFailedException When commit counting fails
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public class PretestedIntegrationAsGitPluginExt extends GitSCMExtension {
* @param allowedNoCommits The amount of commits allowed for integration
*/
@DataBoundConstructor
public PretestedIntegrationAsGitPluginExt(IntegrationStrategy gitIntegrationStrategy, final String integrationBranch, final String repoName, String allowedNoCommits) {
this.gitBridge = new GitBridge(gitIntegrationStrategy,integrationBranch,repoName, Integer.valueOf(allowedNoCommits));
public PretestedIntegrationAsGitPluginExt(IntegrationStrategy gitIntegrationStrategy, final String integrationBranch, final String repoName, int allowedNoCommits) {
this.gitBridge = new GitBridge(gitIntegrationStrategy,integrationBranch,repoName, allowedNoCommits);
}

@DataBoundSetter
Expand Down Expand Up @@ -140,7 +140,7 @@ public Revision decorateRevisionToBuild(GitSCM scm, Run<?, ?> run, GitClient git
} catch (IOException ex) {
LOGGER.log(Level.FINE, "Failed to update build description", ex);
}
gitBridge.setResultInfo("NothingToDo");

gitBridge.updateBuildDescription(run);
throw new GitException("Nothing to do..");
} catch (IntegrationFailedException| UnsupportedConfigurationException e) {
Expand All @@ -149,7 +149,6 @@ public Revision decorateRevisionToBuild(GitSCM scm, Run<?, ?> run, GitClient git
} else {
run.setResult(Result.FAILURE);
}
gitBridge.setResultInfo("MergeFailed");
String logMessage = String.format("%s - decorateRevisionToBuild() - %s - %s", LOG_PREFIX, e.getClass().getSimpleName(), e.getMessage());
listener.getLogger().println(logMessage);
LOGGER.log(Level.SEVERE, logMessage, e);
Expand All @@ -165,14 +164,12 @@ public Revision decorateRevisionToBuild(GitSCM scm, Run<?, ?> run, GitClient git
} else {
run.setResult(Result.FAILURE);
}
gitBridge.setResultInfo("NoCommits");
String logMessage = String.format("%s - decorateRevisionToBuild() - %s - %s", LOG_PREFIX, e.getClass().getSimpleName(), e.getMessage());
listener.getLogger().println(logMessage);
LOGGER.log(Level.SEVERE, logMessage, e);

} catch (IOException e) {
run.setResult(Result.FAILURE);
gitBridge.setResultInfo("UNKNOWN");
gitBridge.updateBuildDescription(run);
String logMessage = String.format("%s - Unexpected error. %n%s", LOG_PREFIX, e.getMessage());
LOGGER.log(Level.SEVERE, logMessage, e);
Expand All @@ -191,7 +188,6 @@ public Revision decorateRevisionToBuild(GitSCM scm, Run<?, ?> run, GitClient git

if ( run.getResult() == null || run.getResult() == Result.SUCCESS ) {
Revision mergeRevision = new GitUtils(listener,git).getRevisionForSHA1(git.revParse(HEAD));
gitBridge.setResultInfo("Build");
mergeRevision.getBranches().add(
new Branch(gitBridge.getExpandedIntegrationBranch(environment), triggeredRevision.getSha1()));
return mergeRevision;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Object pretestedIntegrationAsGitPluginExt(String strategy, String branch,
integrationStrategy = new SquashCommitStrategy();
break;
}
return new PretestedIntegrationAsGitPluginExt((GitIntegrationStrategy)integrationStrategy, branch, repository);
return new PretestedIntegrationAsGitPluginExt(integrationStrategy, branch, repository, Integer.MAX_VALUE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void integrate(AbstractBuild<?, ?> build, Launcher launcher, BuildListene
expandedIntegrationBranch = gitbridge.getIntegrationBranch();
}

if(tryFastForward(buildData.lastBuild.getSHA1(), listener.getLogger(), client, expandedIntegrationBranch )) return;
if(tryFastForward(buildData.lastBuild.getSHA1(), listener.getLogger(), client, gitbridge.getAllowedNoCommits() )) return;
if(tryRebase(buildData.lastBuild.getSHA1(), client, expandedIntegrationBranch )) return;

try {
Expand Down Expand Up @@ -181,7 +181,7 @@ public void integrateAsGitPluginExt(GitSCM scm, Run<?, ?> build, GitClient clien
expandedIntegrationBranch = gitbridge.getIntegrationBranch();
}

if(tryFastForward(buildData.lastBuild.getSHA1(), listener.getLogger(), client, expandedIntegrationBranch )) return;
if(tryFastForward(buildData.lastBuild.getSHA1(), listener.getLogger(), client, gitbridge.getAllowedNoCommits() )) return;
if(tryRebase(buildData.lastBuild.getSHA1(), client, expandedIntegrationBranch )) return;

String expandedBranchName;
Expand Down
Loading