forked from geoffbullen/build-pipeline-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from dalvizu/JENKINS-30801-2
[Fixed JENKINS-30801]
- Loading branch information
Showing
6 changed files
with
206 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ checkstyle-cachefile | |
*.iml | ||
*.ipr | ||
*.iws | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,33 +24,32 @@ | |
*/ | ||
package au.com.centrumsystems.hudson.plugin.buildpipeline; | ||
|
||
import hudson.model.Action; | ||
import hudson.model.Cause; | ||
import hudson.model.FreeStyleBuild; | ||
import hudson.model.ItemGroup; | ||
import hudson.model.TopLevelItem; | ||
import hudson.Launcher; | ||
import hudson.model.*; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
import hudson.model.Cause.UpstreamCause; | ||
import hudson.model.FreeStyleProject; | ||
import hudson.model.Hudson; | ||
import hudson.model.Job; | ||
import hudson.model.Run; | ||
import hudson.security.Permission; | ||
|
||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import hudson.triggers.SCMTrigger; | ||
import jenkins.model.Jenkins; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.Bug; | ||
|
||
import au.com.centrumsystems.hudson.plugin.buildpipeline.trigger.BuildPipelineTrigger; | ||
import org.jvnet.hudson.test.Issue; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.TestBuilder; | ||
import org.jvnet.hudson.test.recipes.LocalData; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.mockito.Mockito.mock; | ||
|
||
/** | ||
* Test Build Pipeline View | ||
|
@@ -256,7 +255,6 @@ public void testGetBuildPipelineForm() throws Exception { | |
// Build project1 | ||
build1 = jenkins.buildAndAssertSuccess(project1); | ||
jenkins.waitUntilNoActivity(); | ||
|
||
// Test a valid case | ||
final BuildPipelineView testView = BuildPipelineViewFactory.getBuildPipelineView(bpViewName, bpViewTitle, new DownstreamProjectGridBuilder(proj1), noOfBuilds, false); | ||
|
||
|
@@ -374,4 +372,112 @@ public ItemGroup<? extends TopLevelItem> getOwnerItemGroup() { | |
}; | ||
} | ||
} | ||
|
||
@Test | ||
@Issue("JENKINS-30801") | ||
public void testRetriggerSuccessfulBuild() throws Exception { | ||
final FreeStyleProject upstreamBuild = jenkins.createFreeStyleProject("upstream"); | ||
final FreeStyleProject downstreamBuild = jenkins.createFreeStyleProject("downstream"); | ||
upstreamBuild.getPublishersList().add(new BuildPipelineTrigger("downstream", null)); | ||
downstreamBuild.getBuildersList().add(new TestBuilder() | ||
{ | ||
This comment has been minimized.
Sorry, something went wrong.
recena
|
||
@Override | ||
public boolean perform(AbstractBuild<?, ?> abstractBuild, Launcher launcher, BuildListener buildListener) | ||
throws InterruptedException, IOException | ||
{ | ||
This comment has been minimized.
Sorry, something went wrong. |
||
abstractBuild.addAction(new MockAction()); | ||
return true; | ||
} | ||
}); | ||
|
||
// Important; we must do this step to ensure that the dependency graphs | ||
// are updated | ||
Hudson.getInstance().rebuildDependencyGraph(); | ||
|
||
// mock the upstream build as being caused by SCM trigger | ||
Cause mockScmTriggerCause = new SCMTrigger.SCMTriggerCause("mock"); | ||
upstreamBuild.scheduleBuild2(0, mockScmTriggerCause); | ||
jenkins.waitUntilNoActivity(); | ||
|
||
// mock trigget the downstream build as being triggered by upstream | ||
ParametersAction parametersAction = new ParametersAction( | ||
Arrays.asList((ParameterValue)new StringParameterValue("foo", "bar"))); | ||
UpstreamCause upstreamCause = new hudson.model.Cause.UpstreamCause( | ||
(Run<?, ?>) upstreamBuild.getLastBuild()); | ||
downstreamBuild.scheduleBuild2(0, upstreamCause, parametersAction); | ||
jenkins.waitUntilNoActivity(); | ||
|
||
BuildPipelineView pipeline = BuildPipelineViewFactory.getBuildPipelineView("pipeline", "", | ||
new DownstreamProjectGridBuilder(upstreamBuild.getFullName()), "1", false); | ||
|
||
jenkins.getInstance().addView(pipeline); | ||
assertNotNull(downstreamBuild.getLastBuild()); | ||
// re-run the build as if we clicked re-run in the UI | ||
pipeline.rerunBuild(downstreamBuild.getLastBuild().getExternalizableId()); | ||
jenkins.waitUntilNoActivity(); | ||
|
||
// MockAction is not copied from one run to another | ||
assertEquals(1, downstreamBuild.getLastBuild().getActions(MockAction.class).size()); | ||
// upstream cause copied | ||
assertEquals(1, downstreamBuild.getLastBuild().getCauses().size()); | ||
// parametersAction copied | ||
assertNotNull(downstreamBuild.getLastBuild().getAction(ParametersAction.class)); | ||
StringParameterValue stringParam = (StringParameterValue) downstreamBuild.getLastBuild() | ||
.getAction(ParametersAction.class).getParameter("foo"); | ||
assertEquals("bar", stringParam.value); | ||
assertEquals(upstreamCause, downstreamBuild.getLastBuild().getCauses().get(0)); | ||
assertEquals(mockScmTriggerCause, upstreamCause.getUpstreamCauses().get(0)); | ||
} | ||
|
||
@Test | ||
public void testFilterUserIdCause() throws Exception { | ||
final FreeStyleProject upstreamBuild = jenkins.createFreeStyleProject("upstream"); | ||
final FreeStyleProject downstreamBuild = jenkins.createFreeStyleProject("downstream"); | ||
upstreamBuild.getPublishersList().add(new BuildPipelineTrigger("downstream", null)); | ||
// Important; we must do this step to ensure that the dependency graphs | ||
// are updated | ||
Hudson.getInstance().rebuildDependencyGraph(); | ||
Cause mockUserIdCause = mock(Cause.UserIdCause.class); | ||
upstreamBuild.scheduleBuild2(0, mockUserIdCause); | ||
jenkins.waitUntilNoActivity(); | ||
UpstreamCause upstreamCause = new hudson.model.Cause.UpstreamCause( | ||
(Run<?, ?>) upstreamBuild.getLastBuild()); | ||
downstreamBuild.scheduleBuild2(0, upstreamCause); | ||
jenkins.waitUntilNoActivity(); | ||
|
||
BuildPipelineView pipeline = BuildPipelineViewFactory.getBuildPipelineView("pipeline", "", | ||
new DownstreamProjectGridBuilder(upstreamBuild.getFullName()), "1", false); | ||
jenkins.getInstance().addView(pipeline); | ||
assertNotNull(downstreamBuild.getLastBuild()); | ||
// re-run the build as if we clicked re-run in the UI | ||
pipeline.rerunBuild(upstreamBuild.getLastBuild().getExternalizableId()); | ||
jenkins.waitUntilNoActivity(); | ||
assertEquals(2, upstreamBuild.getBuilds().size()); | ||
assertNotNull(upstreamBuild.getLastBuild().getCause(Cause.UserIdCause.class)); | ||
assertNotSame(upstreamBuild.getLastBuild().getCause(Cause.UserIdCause.class), | ||
mockUserIdCause); | ||
} | ||
|
||
public static class MockAction implements Action, Serializable { | ||
|
||
private static final long serialVersionUID = 5677631606354259250L; | ||
|
||
@Override | ||
public String getIconFileName() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getUrlName() | ||
{ | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Please, avoid to use wildcard in import statement.