use of hudson.plugins.copyartifact.testutils.FileWriteBuilder in project copyartifact-plugin by jenkinsci.
the class LegacyJobConfigMigrationMonitorMigrationTest method migrate_matrixchild_to_pipeline.
@Test
public void migrate_matrixchild_to_pipeline() throws Exception {
MatrixProject src = j.createProject(MatrixProject.class);
AxisList axisList = new AxisList(new Axis("axis1", "value1", "value2"));
src.setAxes(axisList);
src.getBuildersList().add(new FileWriteBuilder("artifact.txt", "artifact content"));
src.getPublishersList().add(new ArtifactArchiver("**/*"));
j.assertBuildStatusSuccess(src.scheduleBuild2(0));
WorkflowJob dst = j.createProject(WorkflowJob.class);
dst.setDefinition(new CpsFlowDefinition("node {" + "copyArtifacts('" + src.getItem(new Combination(axisList, "value1")).getFullName() + "');" + "}", true));
j.assertBuildStatusSuccess(dst.scheduleBuild2(0));
CopyArtifactConfiguration.get().setMode(CopyArtifactCompatibilityMode.PRODUCTION);
j.assertBuildStatus(Result.FAILURE, dst.scheduleBuild2(0));
assertTrue(applyAutoMigrationToAll());
j.assertBuildStatusSuccess(dst.scheduleBuild2(0));
}
use of hudson.plugins.copyartifact.testutils.FileWriteBuilder in project copyartifact-plugin by jenkinsci.
the class LegacyJobConfigMigrationMonitorMigrationTest method migrate_matrix_to_pipeline.
@Test
public void migrate_matrix_to_pipeline() throws Exception {
MatrixProject src = j.createProject(MatrixProject.class);
src.setAxes(new AxisList(new Axis("axis1", "value1", "value2")));
src.getBuildersList().add(new FileWriteBuilder("artifact.txt", "artifact content"));
src.getPublishersList().add(new ArtifactArchiver("**/*"));
j.assertBuildStatusSuccess(src.scheduleBuild2(0));
WorkflowJob dst = j.createProject(WorkflowJob.class);
dst.setDefinition(new CpsFlowDefinition("node {" + "copyArtifacts('" + src.getFullName() + "');" + "}", true));
j.assertBuildStatusSuccess(dst.scheduleBuild2(0));
CopyArtifactConfiguration.get().setMode(CopyArtifactCompatibilityMode.PRODUCTION);
j.assertBuildStatus(Result.FAILURE, dst.scheduleBuild2(0));
assertTrue(applyAutoMigrationToAll());
j.assertBuildStatusSuccess(dst.scheduleBuild2(0));
}
use of hudson.plugins.copyartifact.testutils.FileWriteBuilder in project copyartifact-plugin by jenkinsci.
the class ParameterizedBuildSelectorTest method testVariableExpression.
/**
* Also accepts variable expression.
*
* @throws Exception
*/
@Test
public void testVariableExpression() throws Exception {
// Prepare an artifact to be copied.
FreeStyleProject copiee = j.createFreeStyleProject();
copiee.getBuildersList().add(new FileWriteBuilder("artifact.txt", "foobar"));
copiee.getPublishersList().add(new ArtifactArchiver("artifact.txt"));
j.assertBuildStatusSuccess(copiee.scheduleBuild2(0));
FreeStyleProject copier = j.createFreeStyleProject();
ParameterDefinition paramDef = new StringParameterDefinition("SELECTOR", "<StatusBuildSelector><stable>true</stable></StatusBuildSelector>");
ParametersDefinitionProperty paramsDef = new ParametersDefinitionProperty(paramDef);
copier.addProperty(paramsDef);
ParameterizedBuildSelector pbs = new ParameterizedBuildSelector("${SELECTOR}");
copier.getBuildersList().add(CopyArtifactUtil.createCopyArtifact(copiee.getFullName(), // parameters
null, pbs, // filter
"**/*", // excludes
"", // flatten
false, // optional
false, // fingerprintArtifacts
false));
FreeStyleBuild b = j.assertBuildStatusSuccess((FreeStyleBuild) copier.scheduleBuild2(0, new ParametersAction(new StringParameterValue("SELECTOR", "<StatusBuildSelector><stable>true</stable></StatusBuildSelector>"))).get());
assertEquals("foobar", b.getWorkspace().child("artifact.txt").readToString());
}
use of hudson.plugins.copyartifact.testutils.FileWriteBuilder in project copyartifact-plugin by jenkinsci.
the class TriggeredBuildSelectorTest method testUseOldestByGlobalSetting.
@Test
public void testUseOldestByGlobalSetting() throws Exception {
TriggeredBuildSelector.DescriptorImpl d = (TriggeredBuildSelector.DescriptorImpl) j.jenkins.getDescriptorOrDie(TriggeredBuildSelector.class);
d.setGlobalUpstreamFilterStrategy(TriggeredBuildSelector.UpstreamFilterStrategy.UseOldest);
FreeStyleProject upstream = j.createFreeStyleProject();
ParameterDefinition paramDef = new StringParameterDefinition("CONTENT", "foo");
ParametersDefinitionProperty paramsDef = new ParametersDefinitionProperty(paramDef);
upstream.addProperty(paramsDef);
FreeStyleProject downstream = j.createFreeStyleProject();
upstream.getBuildersList().add(new FileWriteBuilder("artifact.txt", "${CONTENT}"));
upstream.getPublishersList().add(new ArtifactArchiver("artifact.txt", "", false, false));
upstream.getPublishersList().add(new BuildTrigger(downstream.getName(), Result.SUCCESS));
downstream.getBuildersList().add(CopyArtifactUtil.createCopyArtifact(upstream.getName(), "", new TriggeredBuildSelector(false, TriggeredBuildSelector.UpstreamFilterStrategy.UseGlobalSetting, false), "artifact.txt", "", false, false, true));
// this allows upstream trigger can be merged.
downstream.setQuietPeriod(5);
upstream.save();
downstream.save();
j.jenkins.rebuildDependencyGraph();
// 3 upstream builds.
j.assertBuildStatusSuccess(upstream.scheduleBuild2(0, new Cause.UserCause(), new ParametersAction(new StringParameterValue("CONTENT", "value1"))));
j.assertBuildStatusSuccess(upstream.scheduleBuild2(0, new Cause.UserCause(), new ParametersAction(new StringParameterValue("CONTENT", "value2"))));
j.assertBuildStatusSuccess(upstream.scheduleBuild2(0, new Cause.UserCause(), new ParametersAction(new StringParameterValue("CONTENT", "value3"))));
// wait till downstream will be triggered and completed
j.waitUntilNoActivity();
FreeStyleBuild b = downstream.getLastBuild();
assertNotNull(b);
j.assertBuildStatusSuccess(b);
assertEquals(String.format("upstream triggers seem not to be merged into one downstream build. This means quietPeriod of downstream is too short in this environment: %s", b.getCauses()), 3, Util.filter(b.getCauses(), Cause.UpstreamCause.class).size());
assertEquals("value1", b.getWorkspace().child("artifact.txt").readToString());
}
use of hudson.plugins.copyartifact.testutils.FileWriteBuilder in project copyartifact-plugin by jenkinsci.
the class LastCompletedBuildSelectorTest method testWithPermalinkBuildSelector.
@Test
public void testWithPermalinkBuildSelector() throws Exception {
FreeStyleProject upstream = j.createFreeStyleProject();
FreeStyleProject downstreamLastCompleted = j.createFreeStyleProject();
FreeStyleProject downstreamLast = j.createFreeStyleProject();
upstream.getBuildersList().add(new FileWriteBuilder("artifact.txt", "${BUILD_ID}"));
upstream.getPublishersList().add(new ArtifactArchiver("artifact.txt", "", false, false));
downstreamLastCompleted.getBuildersList().add(new CopyArtifact(upstream.getFullName(), "", new LastCompletedBuildSelector(), "**/*", "", "", false, false, true));
downstreamLastCompleted.getPublishersList().add(new ArtifactArchiver("artifact.txt", "", false, false));
downstreamLast.getBuildersList().add(new CopyArtifact(upstream.getFullName(), "", new PermalinkBuildSelector("lastBuild"), "**/*", "", "", false, false, true));
downstreamLast.getPublishersList().add(new ArtifactArchiver("artifact.txt", "", false, false));
FreeStyleBuild upstreamCompletedBuild = upstream.scheduleBuild2(0).get();
upstream.getBuildersList().add(new SleepBuilder(60000));
upstream.scheduleBuild2(0);
FreeStyleBuild upstreamIncompleteBuild = waitForBuildStarts(upstream, 5000);
FreeStyleBuild downstreamLastCompletedBuild = downstreamLastCompleted.scheduleBuild2(0).get();
FreeStyleBuild downstreamLastBuild = downstreamLast.scheduleBuild2(0).get();
assertTrue(upstreamIncompleteBuild.isBuilding());
upstreamIncompleteBuild.getExecutor().interrupt();
j.assertBuildStatusSuccess(downstreamLastCompletedBuild);
// this fails as upstream have no artifact.
j.assertBuildStatus(Result.FAILURE, downstreamLastBuild);
File artifact = new File(downstreamLastCompletedBuild.getArtifactsDir(), "artifact.txt");
assertEquals(upstreamCompletedBuild.getId(), FileUtils.readFileToString(artifact, "UTF-8"));
}
Aggregations