Skip to content
Permalink
Browse files

Merge pull request #48 from ikedam/feature/JENKINS-14653_MavenWithTri…

…ggeredBuildSelector

[JENKINS-14653] maven with triggered build selector

Conflicts:
	src/main/java/hudson/plugins/copyartifact/TriggeredBuildSelector.java
	src/test/java/hudson/plugins/copyartifact/TriggeredBuildSelectorTest.java
  • Loading branch information...
ikedam committed Oct 11, 2014
2 parents c11b826 + c4ea4eb commit c9809c88174520376501970cb6b8135085eb727a
@@ -25,13 +25,14 @@

import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.ArrayList;
import java.util.List;

import jenkins.model.Jenkins;
import hudson.EnvVars;
import hudson.Extension;
import hudson.matrix.MatrixConfiguration;
import hudson.matrix.MatrixRun;
import hudson.model.Result;
import hudson.model.AbstractProject;
import hudson.model.Cause;
import hudson.model.Cause.UpstreamCause;
import hudson.model.Job;
@@ -140,17 +141,18 @@ public boolean isUseNewest() {
@Override
public Run<?,?> getBuild(Job<?,?> job, EnvVars env, BuildFilter filter, Run<?,?> parent) {
Run<?,?> result = null;
// Upstream job for matrix will be parent project, not individual configuration:
String jobName = job instanceof MatrixConfiguration
? job.getParent().getFullName() : job.getFullName();
// Matrix run is triggered by its parent project, so check causes of parent build:
for (Cause cause : parent instanceof MatrixRun
? ((MatrixRun)parent).getParentBuild().getCauses() : parent.getCauses()) {
// Upstream job for matrix will be parent project, not only individual configuration:
List<String> jobNames = new ArrayList<String>();
jobNames.add(job.getFullName());
if ((job instanceof AbstractProject<?,?>) && ((AbstractProject<?,?>)job).getRootProject() != job) {
jobNames.add(((AbstractProject<?,?>)job).getRootProject().getFullName());
}
for (Cause cause: parent.getCauses()) {
if (cause instanceof UpstreamCause) {
UpstreamCause upstream = (UpstreamCause) cause;
String upstreamProject = upstream.getUpstreamProject();
int upstreamBuild = upstream.getUpstreamBuild();
if (jobName.equals(upstreamProject)) {
if (jobNames.contains(upstreamProject)) {
Run<?,?> run = job.getBuildByNumber(upstreamBuild);
if (run != null && filter.isSelectable(run, env)){
if (
@@ -25,7 +25,11 @@
package hudson.plugins.copyartifact;

import static org.junit.Assert.*;

import java.util.Arrays;

import hudson.Util;
import hudson.maven.MavenModuleSet;
import hudson.model.Cause;
import hudson.model.FreeStyleProject;
import hudson.model.ParametersAction;
@@ -40,6 +44,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.JenkinsRule.WebClient;

@@ -760,4 +765,46 @@ public void testUpstreamWasRemoved() throws Exception {
j.assertBuildStatusSuccess(downstream.getLastBuild());
}
}

@Bug(14653)
@Test
public void testMavenModule() throws Exception {
j.configureDefaultMaven();
MavenModuleSet upstream = j.createMavenProject();
FreeStyleProject downstream = j.createFreeStyleProject();

upstream.setGoals("clean package");
upstream.setScm(new ExtractResourceSCM(getClass().getResource("maven-job.zip")));
upstream.getPublishersList().add(new BuildTrigger(downstream.getName(), Result.SUCCESS));

downstream.getBuildersList().add(new CopyArtifact(
String.format("%s/org.jvnet.hudson.main.test.multimod$moduleB", upstream.getName()),
"",
new TriggeredBuildSelector(false, null),
"**/*",
"",
"",
false,
false,
false
));

upstream.save();
downstream.save();
j.jenkins.rebuildDependencyGraph();

j.assertBuildStatusSuccess(upstream.scheduleBuild2(0));
j.waitUntilNoActivity();

FreeStyleBuild b = downstream.getLastBuild();
j.assertBuildStatusSuccess(b);

assertTrue(
String.format(
"File not found: files are: %s",
Arrays.asList(b.getWorkspace().list("**/*"))
),
b.getWorkspace().child("org.jvnet.hudson.main.test.multimod/moduleB/1.0-SNAPSHOT/moduleB-1.0-SNAPSHOT.jar").exists()
);
}
}

0 comments on commit c9809c8

Please sign in to comment.
You can’t perform that action at this time.