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", "")));
}
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());
}
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());
}
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");
}
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");
}
Aggregations