Search in sources :

Example 16 with StringParameterDefinition

use of hudson.model.StringParameterDefinition in project copyartifact-plugin by jenkinsci.

the class LegacyJobConfigMigrationMonitorTest method setupWorkflowJob.

private void setupWorkflowJob() throws Exception {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    MockAuthorizationStrategy auth = new MockAuthorizationStrategy().grant(Jenkins.ADMINISTER).everywhere().to("admin").grant(Jenkins.READ).onRoot().toEveryone().grant(Computer.BUILD).everywhere().toEveryone();
    j.jenkins.setAuthorizationStrategy(auth);
    FreeStyleProject toBeCopiedAnonymous = j.createFreeStyleProject("to-be-copied_anonymous");
    auth.grant(Item.READ, Item.CONFIGURE).onItems(toBeCopiedAnonymous).toEveryone();
    toBeCopiedAnonymous.getBuildersList().add(new FileWriteBuilder("test.txt", "test"));
    toBeCopiedAnonymous.getPublishersList().add(new ArtifactArchiver("**"));
    // Originally this is configured without AuthorizationMatrixProperty,
    // which results inheriting the global configuration,
    // in contract to that other jobs doesn't inherit the global configuration
    // MockAuthorizationStrategy doesn't provide feature to refuse inheriting
    // in a specific job, so this job is configured to grant Item.READ to everyone,
    // which was originally configured in the global configuration.
    FreeStyleProject toBeCopiedNoauth = j.createFreeStyleProject("to-be-copied_noauth");
    auth.grant(Item.READ).onItems(toBeCopiedNoauth).toEveryone();
    toBeCopiedNoauth.getBuildersList().add(new FileWriteBuilder("test.txt", "test"));
    toBeCopiedNoauth.getPublishersList().add(new ArtifactArchiver("**"));
    FreeStyleProject toBeCopiedRestricted = j.createFreeStyleProject("to-be-copied_restricted");
    auth.grant(Item.READ).onItems(toBeCopiedRestricted).to("leader", "admin");
    toBeCopiedRestricted.getBuildersList().add(new FileWriteBuilder("test.txt", "test"));
    toBeCopiedRestricted.getPublishersList().add(new ArtifactArchiver("**"));
    WorkflowJob copierAnonymous = j.createWorkflow("copier_anonymous", "copyArtifacts(projectName: 'to-be-copied_anonymous');");
    copierAnonymous.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("sourceProject", "")));
    WorkflowJob copierNoauth = j.createWorkflow("copier_noauth", "copyArtifacts(projectName: 'to-be-copied_noauth');");
    copierNoauth.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("sourceProject", "")));
    WorkflowJob copierParam = j.createWorkflow("copier_param", "copyArtifacts(projectName: '${sourceProject}');");
    copierParam.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("sourceProject", "")));
    WorkflowJob copierRestricted = j.createWorkflow("copier_restricted", "copyArtifacts(projectName: 'to-be-copied_restricted');");
    copierRestricted.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("sourceProject", "")));
}
Also used : ArtifactArchiver(hudson.tasks.ArtifactArchiver) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) MockAuthorizationStrategy(org.jvnet.hudson.test.MockAuthorizationStrategy) FileWriteBuilder(hudson.plugins.copyartifact.testutils.FileWriteBuilder) FreeStyleProject(hudson.model.FreeStyleProject) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob)

Example 17 with StringParameterDefinition

use of hudson.model.StringParameterDefinition 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 18 with StringParameterDefinition

use of hudson.model.StringParameterDefinition 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 19 with StringParameterDefinition

use of hudson.model.StringParameterDefinition in project generic-webhook-trigger-plugin by jenkinsci.

the class ParameterActionUtilTest method testThatStringDoesNotKeepItsDefaultValueWhenParameterSupplied.

@Test
public void testThatStringDoesNotKeepItsDefaultValueWhenParameterSupplied() {
    final ParametersDefinitionProperty parametersDefinitionProperty = new ParametersDefinitionProperty(// 
    new StringParameterDefinition("name", "the default value"));
    final Map<String, String> resolvedVariables = // 
    ImmutableMap.<// 
    String, // 
    String>of("name", "this is supplied");
    final ParametersAction actual = createParameterAction(parametersDefinitionProperty, resolvedVariables);
    // 
    assertThat(actual).hasSize(1);
    // 
    assertThat(actual.getAllParameters().get(0).getValue()).isEqualTo("this is supplied");
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) ParametersAction(hudson.model.ParametersAction) Test(org.junit.Test)

Example 20 with StringParameterDefinition

use of hudson.model.StringParameterDefinition in project generic-webhook-trigger-plugin by jenkinsci.

the class ParameterActionUtilTest method testThatStringKeepsItsDefaultValueWhenNoParameterSupplied.

@Test
public void testThatStringKeepsItsDefaultValueWhenNoParameterSupplied() {
    final ParametersDefinitionProperty parametersDefinitionProperty = new ParametersDefinitionProperty(// 
    new StringParameterDefinition("name", "the default value"));
    final Map<String, String> resolvedVariables = // 
    ImmutableMap.<String, String>builder().build();
    final ParametersAction actual = createParameterAction(parametersDefinitionProperty, resolvedVariables);
    // 
    assertThat(actual).hasSize(1);
    // 
    assertThat(actual.getAllParameters().get(0).getValue()).isEqualTo("the default value");
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) ParametersAction(hudson.model.ParametersAction) Test(org.junit.Test)

Aggregations

StringParameterDefinition (hudson.model.StringParameterDefinition)88 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)76 Test (org.junit.Test)71 FreeStyleProject (hudson.model.FreeStyleProject)69 ParametersAction (hudson.model.ParametersAction)44 FreeStyleBuild (hudson.model.FreeStyleBuild)43 StringParameterValue (hudson.model.StringParameterValue)43 Issue (org.jvnet.hudson.test.Issue)25 ParameterDefinition (hudson.model.ParameterDefinition)19 FileWriteBuilder (hudson.plugins.copyartifact.testutils.FileWriteBuilder)15 ArtifactArchiver (hudson.tasks.ArtifactArchiver)15 Shell (hudson.tasks.Shell)15 Cause (hudson.model.Cause)12 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)12 CIMessageNotifier (com.redhat.jenkins.plugins.ci.CIMessageNotifier)10 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)9 JobPropertyImpl (hudson.plugins.promoted_builds.JobPropertyImpl)8 BuildTrigger (hudson.tasks.BuildTrigger)8 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)8 CIBuildTrigger (com.redhat.jenkins.plugins.ci.CIBuildTrigger)7