Search in sources :

Example 36 with FileWriteBuilder

use of hudson.plugins.copyartifact.testutils.FileWriteBuilder in project copyartifact-plugin by jenkinsci.

the class CopyArtifactTest method testPermissionWhenParameterizedForMatrixConfig.

@Test
public void testPermissionWhenParameterizedForMatrixConfig() throws Exception {
    rule.jenkins.setSecurityRealm(rule.createDummySecurityRealm());
    MockAuthorizationStrategy auth = new MockAuthorizationStrategy().grant(Jenkins.READ).onRoot().toEveryone();
    rule.jenkins.setAuthorizationStrategy(auth);
    MatrixProject src = rule.jenkins.createProject(MatrixProject.class, "testMatrix");
    AxisList axisList = new AxisList(new Axis("FOO", "foo", "bar"));
    src.setAxes(axisList);
    auth.grant(Item.READ).onItems(src).toEveryone();
    auth.grant(Item.READ).onItems(src.getItem(new Combination(axisList, "foo"))).toEveryone();
    auth.grant(Item.READ).onItems(src.getItem(new Combination(axisList, "bar"))).toEveryone();
    src.getBuildersList().add(new FileWriteBuilder("foo.txt", "foo"));
    src.getPublishersList().add(new ArtifactArchiver("*.txt"));
    rule.assertBuildStatusSuccess(src.scheduleBuild2(0));
    FreeStyleProject p = createProject("testMatrix/FOO=$FOO", null, "", "", false, false, false, true);
    ParameterDefinition paramDef = new StringParameterDefinition("FOO", "FOO");
    ParametersDefinitionProperty paramsDef = new ParametersDefinitionProperty(paramDef);
    p.addProperty(paramsDef);
    // Build step should succeed when this parameter expands to a job accessible to
    // authenticated users, even when selecting a single matrix config, not the parent job:
    FreeStyleBuild b = p.scheduleBuild2(0, new UserCause(), new ParametersAction(new StringParameterValue("FOO", "foo"))).get();
    assertFile(true, "foo.txt", b);
    rule.assertBuildStatusSuccess(b);
}
Also used : AxisList(hudson.matrix.AxisList) ArtifactArchiver(hudson.tasks.ArtifactArchiver) UserCause(hudson.model.Cause.UserCause) MatrixProject(hudson.matrix.MatrixProject) Combination(hudson.matrix.Combination) MockAuthorizationStrategy(org.jvnet.hudson.test.MockAuthorizationStrategy) FileWriteBuilder(hudson.plugins.copyartifact.testutils.FileWriteBuilder) TextAxis(hudson.matrix.TextAxis) Axis(hudson.matrix.Axis) Test(org.junit.Test)

Example 37 with FileWriteBuilder

use of hudson.plugins.copyartifact.testutils.FileWriteBuilder in project copyartifact-plugin by jenkinsci.

the class CopyArtifactTest method testEnvDataInMavenProject.

@Issue("JENKINS-16028")
@Test
public void testEnvDataInMavenProject() throws Exception {
    FreeStyleProject upstream = rule.createFreeStyleProject("upstream");
    upstream.getBuildersList().add(new FileWriteBuilder("artifact.txt", "foobar"));
    upstream.getPublishersList().add(new ArtifactArchiver("**/*", "", false, false));
    FreeStyleBuild upstreamBuild = upstream.scheduleBuild2(0).get();
    rule.assertBuildStatusSuccess(upstreamBuild);
    MavenModuleSet downstream = setupMavenJob();
    downstream.getPrebuilders().add(CopyArtifactUtil.createCopyArtifact("upstream", "", new SpecificBuildSelector(Integer.toString(upstreamBuild.getNumber())), "**/*", "", "", false, false, false));
    CaptureEnvironmentBuilder envStep = new CaptureEnvironmentBuilder();
    downstream.getPrebuilders().add(envStep);
    MavenModuleSetBuild downstreamBuild = downstream.scheduleBuild2(0).get();
    rule.assertBuildStatusSuccess(downstreamBuild);
    assertFile(true, "artifact.txt", downstreamBuild);
    assertEquals(Integer.toString(upstreamBuild.getNumber()), envStep.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_UPSTREAM"));
}
Also used : MavenModuleSetBuild(hudson.maven.MavenModuleSetBuild) ArtifactArchiver(hudson.tasks.ArtifactArchiver) FileWriteBuilder(hudson.plugins.copyartifact.testutils.FileWriteBuilder) CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder) MavenModuleSet(hudson.maven.MavenModuleSet) Issue(org.jvnet.hudson.test.Issue) 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