Search in sources :

Example 11 with FileWriteBuilder

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));
}
Also used : AxisList(hudson.matrix.AxisList) ArtifactArchiver(hudson.tasks.ArtifactArchiver) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) Combination(hudson.matrix.Combination) FileWriteBuilder(hudson.plugins.copyartifact.testutils.FileWriteBuilder) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) MatrixProject(hudson.matrix.MatrixProject) Axis(hudson.matrix.Axis) WorkflowMultiBranchProjectTest(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProjectTest) Test(org.junit.Test)

Example 12 with FileWriteBuilder

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));
}
Also used : AxisList(hudson.matrix.AxisList) ArtifactArchiver(hudson.tasks.ArtifactArchiver) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) FileWriteBuilder(hudson.plugins.copyartifact.testutils.FileWriteBuilder) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) MatrixProject(hudson.matrix.MatrixProject) Axis(hudson.matrix.Axis) WorkflowMultiBranchProjectTest(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProjectTest) Test(org.junit.Test)

Example 13 with FileWriteBuilder

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());
}
Also used : ArtifactArchiver(hudson.tasks.ArtifactArchiver) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) FileWriteBuilder(hudson.plugins.copyartifact.testutils.FileWriteBuilder) StringParameterValue(hudson.model.StringParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) ParametersAction(hudson.model.ParametersAction) StringParameterDefinition(hudson.model.StringParameterDefinition) ParameterDefinition(hudson.model.ParameterDefinition) Test(org.junit.Test)

Example 14 with FileWriteBuilder

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());
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) ArtifactArchiver(hudson.tasks.ArtifactArchiver) StringParameterValue(hudson.model.StringParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) ParametersAction(hudson.model.ParametersAction) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) FileWriteBuilder(hudson.plugins.copyartifact.testutils.FileWriteBuilder) Cause(hudson.model.Cause) BuildTrigger(hudson.tasks.BuildTrigger) ParameterDefinition(hudson.model.ParameterDefinition) StringParameterDefinition(hudson.model.StringParameterDefinition) Test(org.junit.Test)

Example 15 with FileWriteBuilder

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"));
}
Also used : ArtifactArchiver(hudson.tasks.ArtifactArchiver) FileWriteBuilder(hudson.plugins.copyartifact.testutils.FileWriteBuilder) SleepBuilder(org.jvnet.hudson.test.SleepBuilder) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) File(java.io.File) Test(org.junit.Test)

Aggregations

FileWriteBuilder (hudson.plugins.copyartifact.testutils.FileWriteBuilder)37 ArtifactArchiver (hudson.tasks.ArtifactArchiver)37 Test (org.junit.Test)32 FreeStyleProject (hudson.model.FreeStyleProject)26 FreeStyleBuild (hudson.model.FreeStyleBuild)17 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)15 StringParameterDefinition (hudson.model.StringParameterDefinition)15 ParametersAction (hudson.model.ParametersAction)13 StringParameterValue (hudson.model.StringParameterValue)13 ParameterDefinition (hudson.model.ParameterDefinition)11 BuildTrigger (hudson.tasks.BuildTrigger)11 MockAuthorizationStrategy (org.jvnet.hudson.test.MockAuthorizationStrategy)11 Cause (hudson.model.Cause)10 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)9 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)6 CopyArtifact (hudson.plugins.copyartifact.CopyArtifact)4 File (java.io.File)4 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)4 Axis (hudson.matrix.Axis)3 AxisList (hudson.matrix.AxisList)3