Skip to content

Commit

Permalink
Fixed integration tests. #138
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNielsen committed Sep 7, 2018
1 parent a639e75 commit b564d02
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 99 deletions.
75 changes: 3 additions & 72 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
Those updates will only be visible to people who have enabled the experimental update center.
Example of a beta: 3.0.0-beta.1-SNAPSHOT
-->
<version>3.0.2-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<packaging>hpi</packaging>


<properties>
<jenkins.version>2.19.4</jenkins.version>
<jenkins-test-harness.version>2.24</jenkins-test-harness.version>
<java.version>8</java.version>
</properties>


<developers>
<developer>
<id>praqma</id>
Expand Down Expand Up @@ -94,22 +94,6 @@
<compatibleSinceVersion>3.0.0</compatibleSinceVersion>
</configuration>
</plugin>

<!--
Use java 1.8. We need this for our testing environment. Java 7 was EOL last year
and i was starting to get some wierd errors with FindBugs plugin. Plugins also require
Java 7 with the version of Jenkins we're using so i decided to move to Java 7 which also soon
is EOL.
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<!--
Allows integration tests to clean test environment before build fails
use 'mvn verify' to run integration tests to allow 'post-integration-test' phase
Expand Down Expand Up @@ -144,41 +128,11 @@
</excludes>
</configuration>
</plugin>

<!--
Generate coverate reports based on instrumented tests.
It does not get automatically executed, but invokes the execution of the
lifecycle phase test prior to executing itself.
Run cobertura:cobertura goal in the build pipeline to get coverage reports
in html and xml formats.
It is considered a Maven report and outputs to site-directory, but plugin needs
mention in the report section as well to include it in the site report.
-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.6</version>
<configuration>
<format>xml</format> <!-- Jenkins uses the xml format -->
<check />
</configuration>
</plugin>
</plugins>
</build>


<dependencies>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>4.5.3.201708160445-r</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand Down Expand Up @@ -223,13 +177,6 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>multiple-scms</artifactId>
<version>0.6</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>job-dsl</artifactId>
Expand All @@ -240,7 +187,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
<version>1.11</version>
<version>1.13</version>
<optional>true</optional>
</dependency>

Expand All @@ -266,24 +213,8 @@
<version>3.0.1</version>
</dependency>

<!--
Added because of multijob plugin and maven job's depend on two older ant libraries.
We need to use the newest as plugins are not forwards compatible.
-->
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.9.2</version>
<optional>true</optional>
<scope>test</scope>
</dependency>

</dependencies>

<!--
We need to have this section because maven.jenkins-ci.org now uses a new
url. We rely on older Jenkins version so this needs to be overridden.
-->
<distributionManagement>
<repository>
<id>maven.jenkins-ci.org</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void perform(Run<?, ?> run, FilePath ws, Launcher launcher, TaskListener
String triggeredBranch = "n/a";
String integrationBranch = "n/a";
String integrationRepo = null;
if( ! run.getActions(PretestTriggerCommitAction.class).isEmpty()) {
if(!run.getActions(PretestTriggerCommitAction.class).isEmpty()) {
triggeredBranch = run.getAction(PretestTriggerCommitAction.class).triggerBranch.getName();
integrationBranch = run.getAction(PretestTriggerCommitAction.class).integrationBranch;
integrationRepo = run.getAction(PretestTriggerCommitAction.class).integrationRepo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ private void doTheIntegration(Run build, TaskListener listener, GitBridge gitbri
LOGGER.log(Level.INFO, String.format(GitMessages.LOG_PREFIX+ "Collecting author of last commit on development branch"));
String commitMsg = String.format("%s%n%s", headerLine, commits);
commitMessage = commitMsg.replaceAll("\"", "'");
} else {
logMessage = String.format(GitMessages.LOG_PREFIX+ "Using short commit message");
LOGGER.log(Level.INFO, logMessage);
listener.getLogger().println(logMessage);
}

// Collect author
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.apache.commons.lang.StringUtils;
import org.eclipse.jgit.lib.ObjectId;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.multiplescms.MultiSCM;
import org.jenkinsci.plugins.pretestedintegration.AbstractSCMBridge;
import org.jenkinsci.plugins.pretestedintegration.IntegrationStrategy;
import org.jenkinsci.plugins.pretestedintegration.IntegrationStrategyDescriptor;
Expand All @@ -19,6 +18,7 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

import javax.annotation.CheckForNull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -163,23 +163,15 @@ public static void updateBuildDescription(Run<?, ?> run, TaskListener listener,
* @param build The Build
* @param listener The BuildListener
* @return the Git SCM for the relevant build data.
* @throws InterruptedException
* When no matching SCMs are found
* @throws NothingToDoException
* When no relevant BuildData is found.
* @throws UnsupportedConfigurationException
* When multiple, ambiguous relevant BuildDatas are found.
*/
protected GitSCM findScm(AbstractBuild<?, ?> build, TaskListener listener) throws IOException, InterruptedException {
@CheckForNull
protected GitSCM findScm(AbstractBuild<?, ?> build, TaskListener listener) {
SCM scm = build.getProject().getScm();
if (scm instanceof GitSCM) {
GitSCM gitScm = (GitSCM) scm;
LOGGER.fine(String.format("Found GitSCM"));
return gitScm;
}
if (scm instanceof MultiSCM) {
throw new InterruptedException("[PREINT] MultiSCM is no longer supported");
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,21 @@ public Revision decorateRevisionToBuild(
Branch triggeredBranch = null;
if ( triggeredRevision.getBranches().isEmpty() ) {
run.setResult(Result.NOT_BUILT);
String logMessage = String.format("%s - No branch on revision hence we cannot built - leaving workspace: %s but dont build", LOG_PREFIX, expandedIntegrationBranch);
String logMessage = String.format("%s - No branch on revision which we cannot handle - leaving workspace: %s and set result to NOT_BUILT", LOG_PREFIX, expandedIntegrationBranch);
listener.getLogger().println(logMessage);
} else {
// TODO: Should this be last branch in stead of?
Branch triggeredBranchDraft = triggeredRevision.getBranches().iterator().next();
triggeredBranch = new Branch(triggeredBranchDraft.getName().replaceFirst("refs/remotes/", ""), triggeredBranchDraft.getSHA1());
}

if( ! run.getActions(PretestTriggerCommitAction.class).isEmpty() ) {
if(!run.getActions(PretestTriggerCommitAction.class).isEmpty() ) {
run.setResult(Result.FAILURE);
String logMessage = String.format("%s ERROR Likely misconfigered. Currently it is not supported to integrate twice in a build. It is likely because of Pipeline preSCM step or multiSCM. Please see https://github.com/Praqma/pretested-integration-plugin/issues/133 for details about Pipeline preSCM support. If it is neither scenarios, please report it", LOG_PREFIX );
listener.getLogger().println(logMessage);
}

if (run.getResult() == null || run.getResult() == Result.SUCCESS ) {

try {
gitBridge.evalBranchConfigurations(triggeredBranch, expandedIntegrationBranch, expandedRepo);
listener.getLogger().println(String.format(LOG_PREFIX + "Checking out integration branch %s:", expandedIntegrationBranch));
Expand All @@ -141,8 +140,11 @@ public Revision decorateRevisionToBuild(
String logMessage = String.format("%s - setUp() - NothingToDoException - %s", LOG_PREFIX, e.getMessage());
listener.getLogger().println(logMessage);
LOGGER.log(Level.SEVERE, logMessage, e);
//Only do this when polling and we have an object
if(scm.getBuildData(run) != null) {
scm.getBuildData(run).saveBuild(new Build(marked, triggeredRevision, run.getNumber(), run.getResult()));
}
// Leave the workspace as we were triggered, so postbuild step can report the correct branch
scm.getBuildData(run).saveBuild(new Build(marked, triggeredRevision, run.getNumber(), run.getResult()));
git.checkout().ref(triggeredBranch.getName()).execute();
} catch (IntegrationFailedException | EstablishingWorkspaceFailedException | UnsupportedConfigurationException e) {
run.setResult(Result.FAILURE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public class ChangelessBranchFailsBuildIT {

private Repository repository;

private final String res = "there was nothing to merge";

@After
public void tearDown() throws Exception{
TestUtilsFactory.destroyRepo(repository);
Expand All @@ -40,7 +38,6 @@ public void squash_changelessBranchFailsBuild() throws Exception {
String console = jenkins.createWebClient().getPage(build, "console").asText();
System.out.println(console);
jenkins.assertBuildStatus(Result.NOT_BUILT, build);
assertTrue(console.contains(res));
}

@Test
Expand All @@ -52,6 +49,5 @@ public void accumulated_changelessBranchFailsBuild() throws Exception {
String console = jenkins.createWebClient().getPage(build, "console").asText();
System.out.println(console);
jenkins.assertBuildStatus(Result.NOT_BUILT, build);
assertTrue(console.contains(res));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void oneBuildBasicMergeFailure() throws Exception {
TestUtilsFactory.triggerProject(project);
jenkinsRule.waitUntilNoActivityUpTo(60000);
jenkinsRule.assertBuildStatus(Result.FAILURE, project.getLastBuild());
assertEquals("3 runs for this particular matrix build", 3, project.getLastBuild().getRuns().size());
assertEquals("0 runs for this particular matrix build. We never go to any of the actual subruns", 0, project.getLastBuild().getRuns().size());
}

}
13 changes: 9 additions & 4 deletions src/test/resources/EndUserTesting/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ def integrationBranch = 'master' + pattern

node {
stage ('Checkout'){
checkout scm
/**
checkout([
// checkout scm
///**
try {
checkout([
$class: 'GitSCM',
branches: [[name: triggerBranchPattern ]],
userRemoteConfigs: [[
Expand All @@ -28,7 +29,11 @@ node {
[$class: 'PruneStaleBranch']
]
])
*/
} catch(Exception e) {
echo "Leave further processing to publisher"
}

// */
// try {
// sh '''
// if [ -e ./build_failed.md ]; then
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
<daysToKeep>-1</daysToKeep>
<numToKeep>-1</numToKeep>
</orphanedItemStrategy>
<triggers/>
<triggers>
<com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger plugin="[email protected]">
<spec>* * * * *</spec>
<interval>60000</interval>
</com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger>
</triggers>
<sources class="jenkins.branch.MultiBranchProject$BranchSourceList" plugin="[email protected]">
<data>
<jenkins.branch.BranchSource>
Expand All @@ -38,7 +43,7 @@
<traits>
<jenkins.plugins.git.traits.BranchDiscoveryTrait/>
<jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait plugin="[email protected]">
<includes>*/readyMultiBranchPipePreSCM/*</includes>
<includes>readyMultiBranchPipePreSCM/*</includes>
<excludes></excludes>
</jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait>
</traits>
Expand Down

0 comments on commit b564d02

Please sign in to comment.