use of hudson.model.StringParameterDefinition in project branch-api-plugin by jenkinsci.
the class ParameterDefinitionBranchPropertyTest method parametersAreConfiguredOnBranchJobs.
@Test
public void parametersAreConfiguredOnBranchJobs() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
BranchSource source = new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches()));
ParameterDefinitionBranchPropertyImpl instance = new ParameterDefinitionBranchPropertyImpl();
instance.setParameterDefinitions(Collections.<ParameterDefinition>singletonList(new StringParameterDefinition("PARAM_STR", "PARAM_DEFAULT_0812673", "The param")));
source.setStrategy(new DefaultBranchPropertyStrategy(new BranchProperty[] { instance, new BasicDummyStepBranchProperty() }));
prj.getSourcesList().add(source);
prj.scheduleBuild(0);
r.waitUntilNoActivity();
r.assertLogContains("PARAM_STR=PARAM_DEFAULT_0812673", prj.getItem("master").getLastBuild());
}
}
use of hudson.model.StringParameterDefinition in project branch-api-plugin by jenkinsci.
the class ParameterDefinitionBranchPropertyTest method configRoundtrip.
@Test
public void configRoundtrip() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
BranchSource source = new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches()));
ParameterDefinitionBranchPropertyImpl instance = new ParameterDefinitionBranchPropertyImpl();
instance.setParameterDefinitions(Collections.<ParameterDefinition>singletonList(new StringParameterDefinition("PARAM_STR", "PARAM_DEFAULT_0812673", "The param")));
source.setStrategy(new DefaultBranchPropertyStrategy(new BranchProperty[] { instance, new BasicDummyStepBranchProperty() }));
prj.getSourcesList().add(source);
r.configRoundtrip(prj);
assertThat(prj.getSources().get(0).getStrategy(), instanceOf(DefaultBranchPropertyStrategy.class));
DefaultBranchPropertyStrategy strategy = (DefaultBranchPropertyStrategy) prj.getSources().get(0).getStrategy();
assertThat(strategy.getProps().get(0), instanceOf(ParameterDefinitionBranchPropertyImpl.class));
ParameterDefinitionBranchPropertyImpl property = (ParameterDefinitionBranchPropertyImpl) strategy.getProps().get(0);
assertThat(property.getParameterDefinitions(), contains(allOf(instanceOf(StringParameterDefinition.class), hasProperty("name", is("PARAM_STR")), hasProperty("defaultValue", is("PARAM_DEFAULT_0812673")), hasProperty("description", is("The param")))));
}
}
use of hudson.model.StringParameterDefinition in project branch-api-plugin by jenkinsci.
the class RateLimitBranchPropertyTest method rateLimitsConcurrentBuilds.
@Test
public void rateLimitsConcurrentBuilds() throws Exception {
int rate = 1000;
try (final MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
BranchSource source = new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches()));
BasicParameterDefinitionBranchProperty p = new BasicParameterDefinitionBranchProperty();
p.setParameterDefinitions(Collections.singletonList(new StringParameterDefinition("FOO", "BAR")));
source.setStrategy(new DefaultBranchPropertyStrategy(new BranchProperty[] { new RateLimitBranchProperty(rate, "hour", false), new ConcurrentBuildBranchProperty(), p }));
prj.getSourcesList().add(source);
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
FreeStyleProject master = prj.getItem("master");
master.setQuietPeriod(0);
assertThat(master.getProperties(), hasEntry(instanceOf(RateLimitBranchProperty.JobPropertyImpl.DescriptorImpl.class), allOf(instanceOf(RateLimitBranchProperty.JobPropertyImpl.class), hasProperty("count", is(rate)), hasProperty("durationName", is("hour")))));
assertThat(master.isInQueue(), is(false));
assertThat(master.getQueueItem(), nullValue());
QueueTaskFuture<FreeStyleBuild> future = master.scheduleBuild2(0);
QueueTaskFuture<FreeStyleBuild> future2 = master.scheduleBuild2(0, (Cause) null, (Action) new ParametersAction(Collections.singletonList(new StringParameterValue("FOO", "MANCHU"))));
assertThat(future, not(is(future2)));
// let the item get added to the queue
while (!master.isInQueue()) {
Thread.yield();
}
long startTime = System.currentTimeMillis();
assertThat(master.isInQueue(), is(true));
// while it is in the queue, until queue maintenance takes place, it will not be flagged as blocked
// since we cannot know when queue maintenance happens from the periodic task
// we cannot assert any value of isBlocked() on this side of maintenance
Queue.getInstance().maintain();
assertThat(master.getQueueItem().isBlocked(), is(true));
assertThat(master.getQueueItem().getCauseOfBlockage().getShortDescription().toLowerCase(), containsString("throttle"));
// now we wait for the start... invoking queue maintain every 100ms so that the queue
// will pick up more responsively than the default 5s
Future<FreeStyleBuild> startCondition = future.getStartCondition();
// at least 5 times the expected delay
long midTime = startTime + 60 * 60 / rate * 1000L * 5;
while (!startCondition.isDone() && System.currentTimeMillis() < midTime) {
Queue.getInstance().maintain();
Thread.sleep(100);
}
assertThat(startCondition.isDone(), is(true));
assertThat(master.isInQueue(), is(true));
FreeStyleBuild firstBuild = startCondition.get();
// now we wait for the start... invoking queue maintain every 100ms so that the queue
// will pick up more responsively than the default 5s
startCondition = future2.getStartCondition();
// at least 5 times the expected delay
long endTime = startTime + 60 * 60 / rate * 1000L * 5;
while (!startCondition.isDone() && System.currentTimeMillis() < endTime) {
Queue.getInstance().maintain();
Thread.sleep(100);
}
assertThat(startCondition.isDone(), is(true));
assertThat(master.isInQueue(), is(false));
FreeStyleBuild secondBuild = startCondition.get();
// it can take more than the requested delay... that's ok, but it should not be
// more than 500ms longer (i.e. 5 of our Queue.maintain loops above)
final long delay = (long) (60.f * 60.f / rate * 1000);
assumeThat("At least the rate implied delay but no more than 500ms longer", secondBuild.getStartTimeInMillis() - firstBuild.getStartTimeInMillis(), allOf(greaterThanOrEqualTo(delay - 200L), lessThanOrEqualTo(delay + 500L)));
future.get();
}
}
use of hudson.model.StringParameterDefinition in project jms-messaging-plugin by jenkinsci.
the class SharedMessagingPluginIntegrationTest method _testSimpleCIEventTriggerWithDefaultValue.
public void _testSimpleCIEventTriggerWithDefaultValue() throws Exception {
FreeStyleProject jobA = j.createFreeStyleProject();
jobA.getBuildersList().add(new Shell("echo hello $DEFAULTPARAM"));
jobA.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("CI_MESSAGE", "", ""), new StringParameterDefinition("DEFAULTPARAM", "world", "")));
attachTrigger(new CIBuildTrigger(false, Collections.singletonList(getSubscriberProviderData(null, null, null))), jobA);
FreeStyleProject jobB = j.createFreeStyleProject();
jobB.getPublishersList().add(new CIMessageNotifier(getPublisherProviderData(null, null, null, "Hello World")));
j.buildAndAssertSuccess(jobB);
waitUntilScheduledBuildCompletes();
j.assertBuildStatusSuccess(jobA.getLastBuild());
j.assertLogContains("hello world", jobA.getLastBuild());
FreeStyleBuild build = jobA.scheduleBuild2(0, new ParametersAction(new StringParameterValue("DEFAULTPARAM", "scott", ""))).get();
j.assertBuildStatusSuccess(build);
j.assertLogContains("hello scott", build);
}
use of hudson.model.StringParameterDefinition in project jms-messaging-plugin by jenkinsci.
the class SharedMessagingPluginIntegrationTest method _testSimpleCIEventTriggerWithTopicOverrideAndVariableTopic.
public void _testSimpleCIEventTriggerWithTopicOverrideAndVariableTopic() throws Exception {
FreeStyleProject jobA = j.createFreeStyleProject();
attachTrigger(new CIBuildTrigger(false, Collections.singletonList(getSubscriberProviderData("org.fedoraproject.my-topic", null, "CI_TYPE = 'code-quality-checks-done' and CI_STATUS = 'failed'"))), jobA);
jobA.getBuildersList().add(new Shell("echo CI_TYPE = $CI_TYPE"));
FreeStyleProject jobB = j.createFreeStyleProject();
jobB.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("MY_TOPIC", "org.fedoraproject.my-topic", "")));
jobB.getPublishersList().add(new CIMessageNotifier(getPublisherProviderData("$MY_TOPIC", MessageUtils.MESSAGE_TYPE.CodeQualityChecksDone, "CI_STATUS = failed", null)));
j.buildAndAssertSuccess(jobB);
waitUntilScheduledBuildCompletes();
j.assertBuildStatusSuccess(jobA.getLastBuild());
j.assertLogContains("echo CI_TYPE = code-quality-checks-done", jobA.getLastBuild());
}
Aggregations