Skip to content

Commit

Permalink
Praqmagh-59 Draft for changed Jenkinsfile handling if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
bicschneider committed Aug 31, 2017
1 parent 93b64b6 commit b70be04
Showing 1 changed file with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import org.jenkinsci.plugins.pretestedintegration.IntegrationStrategy;
import org.jenkinsci.plugins.pretestedintegration.IntegrationStrategyDescriptor;
import org.jenkinsci.plugins.pretestedintegration.exceptions.*;
import org.jenkinsci.plugins.workflow.flow.FlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.*;
Expand Down Expand Up @@ -119,17 +122,24 @@ public Revision decorateRevisionToBuild(
try {
gitBridge.evalBranchConfigurations(triggeredBranch, expandedIntegrationBranch, expandedRepo);

ChangelogCommand changelog = git.changelog();
changelog.includes(triggeredRevision.getSha1());
Writer out = new StringWriter();
listener.getLogger().println("Using 'Changelog to branch' strategy.");
changelog.excludes(expandedRepo + "/" + expandedIntegrationBranch);
changelog.to(out).execute();
if (out.toString().contains("Jenkinsfile")){
listener.getLogger().println(String.format("%s You have changed Jenkinsfile", LOG_PREFIX));
if ( run instanceof WorkflowRun ) {
WorkflowJob wf = (WorkflowJob) run.getParent();
FlowDefinition fd = wf.getDefinition();
Integer hash = fd.hashCode();
ChangelogCommand changelog = git.changelog();
changelog.includes(triggeredRevision.getSha1());
Writer out = new StringWriter();
listener.getLogger().println("Using 'Changelog to branch' strategy.");
changelog.excludes(expandedRepo + "/" + expandedIntegrationBranch);
changelog.to(out).execute();
if (out.toString().contains("Jenkinsfile")){
listener.getLogger().println(String.format("%s You have changed Jenkinsfile", LOG_PREFIX));
// throw new IntegrationFailedException("You have changed Jenkinsfile");
}

}


listener.getLogger().println(String.format(LOG_PREFIX + "Checking out integration branch %s:", expandedIntegrationBranch));
git.checkout().branch(expandedIntegrationBranch).ref(expandedRepo + "/" + expandedIntegrationBranch).deleteBranchIfExist(true).execute();
((GitIntegrationStrategy) gitBridge.integrationStrategy).integrateAsGitPluginExt(scm, run, git, listener, marked, triggeredRevision, gitBridge);
Expand Down

0 comments on commit b70be04

Please sign in to comment.