use of hudson.model.StringParameterDefinition in project branch-api-plugin by jenkinsci.
the class RateLimitBranchPropertyTest method rateLimitsUserBoost.
@Test
public void rateLimitsUserBoost() throws Exception {
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(1, "hour", true), 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(1)), hasProperty("durationName", is("hour")))));
assertThat(master.isInQueue(), is(false));
assertThat(master.getQueueItem(), nullValue());
// trigger first build... this should start as it is the first build
QueueTaskFuture<FreeStyleBuild> future = master.scheduleBuild2(0);
// 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
LOGGER.info("Waiting for first build");
Future<FreeStyleBuild> startCondition = future.getStartCondition();
long midTime = startTime + BUILT_TO_START_DELAY_MILLIS;
while (!startCondition.isDone() && System.currentTimeMillis() < midTime) {
Queue.getInstance().maintain();
Thread.sleep(100);
}
assertThat(startCondition.isDone(), is(false));
assertThat(master.isInQueue(), is(true));
// trigger second build, this should be blocked as it is not user caused
LOGGER.info("Checking second build blocked");
future = master.scheduleBuild2(0);
// 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 = future.getStartCondition();
// it's ok that the end time is short, we will re-verify the not-started at the end after waiting
// for a request submitted after to have been built.
long endTime = System.currentTimeMillis() + BUILD_TO_NOT_START_DELAY_MILLIS;
while (!startCondition.isDone() && System.currentTimeMillis() < endTime) {
Queue.getInstance().maintain();
Thread.sleep(100);
}
assertThat(startCondition.isDone(), is(false));
assertThat(master.isInQueue(), is(true));
// now we trigger a user build... it should skip the queue
QueueTaskFuture<FreeStyleBuild> future2 = master.scheduleBuild2(0, new Cause.UserIdCause(), (Action) new ParametersAction(Collections.singletonList(new StringParameterValue("FOO", "MANCHU"))));
// now we wait for the start... invoking queue maintain every 100ms so that the queue
// will pick up more responsively than the default 5s
LOGGER.info("Checking user submitted build skips");
startCondition = future2.getStartCondition();
endTime = System.currentTimeMillis() + BUILT_TO_START_DELAY_MILLIS;
while (!startCondition.isDone() && System.currentTimeMillis() < endTime) {
Queue.getInstance().maintain();
Thread.sleep(100);
}
assertThat("Non user triggered build still blocked", future.getStartCondition().isDone(), is(false));
assertThat("User triggered build successful", future2.getStartCondition().isDone(), is(true));
assertThat(master.isInQueue(), is(true));
future.cancel(true);
}
}
use of hudson.model.StringParameterDefinition in project jms-messaging-plugin by jenkinsci.
the class CIBuildTrigger method getDefinedParameters.
private List<ParameterValue> getDefinedParameters(Job<?, ?> project) {
List<ParameterValue> parameters = new ArrayList<>();
ParametersDefinitionProperty properties = project.getProperty(ParametersDefinitionProperty.class);
if (properties != null && properties.getParameterDefinitions() != null) {
for (ParameterDefinition paramDef : properties.getParameterDefinitions()) {
ParameterValue param = null;
if (paramDef instanceof StringParameterDefinition) {
param = new StringParameterValue(paramDef.getName(), ((StringParameterDefinition) paramDef).getDefaultValue());
}
if (paramDef instanceof TextParameterDefinition) {
param = new TextParameterValue(paramDef.getName(), ((TextParameterDefinition) paramDef).getDefaultValue());
}
if (paramDef instanceof BooleanParameterDefinition) {
BooleanParameterValue defaultParameterValue = ((BooleanParameterDefinition) paramDef).getDefaultParameterValue();
param = new BooleanParameterValue(paramDef.getName(), Boolean.TRUE.equals(Objects.requireNonNull(defaultParameterValue).getValue()));
}
if (paramDef instanceof ChoiceParameterDefinition) {
param = ((ChoiceParameterDefinition) paramDef).getDefaultParameterValue();
}
if (param != null) {
parameters.add(param);
}
}
}
return parameters;
}
use of hudson.model.StringParameterDefinition in project jms-messaging-plugin by jenkinsci.
the class SharedMessagingPluginIntegrationTest method _testSimpleCIEventTriggerWithCheckWithTopicOverrideAndVariableTopic.
public void _testSimpleCIEventTriggerWithCheckWithTopicOverrideAndVariableTopic() throws Exception {
FreeStyleProject jobA = j.createFreeStyleProject();
attachTrigger(new CIBuildTrigger(false, Collections.singletonList(getSubscriberProviderData("org.fedoraproject.my-topic", null, null, new MsgCheck(MESSAGE_CHECK_FIELD, MESSAGE_CHECK_VALUE)))), jobA);
jobA.getBuildersList().add(new Shell("echo job ran"));
FreeStyleProject jobB = j.createFreeStyleProject();
jobB.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("MY_TOPIC", "org.fedoraproject.my-topic", "")));
jobB.getPublishersList().add(new CIMessageNotifier(getPublisherProviderData("$MY_TOPIC", null, null, MESSAGE_CHECK_CONTENT)));
j.buildAndAssertSuccess(jobB);
waitUntilScheduledBuildCompletes();
j.assertBuildStatusSuccess(jobA.getLastBuild());
j.assertLogContains("echo job ran", jobA.getLastBuild());
}
use of hudson.model.StringParameterDefinition in project jms-messaging-plugin by jenkinsci.
the class SharedMessagingPluginIntegrationTest method _testSimpleCIEventSubscribeWithNoParamOverride.
public void _testSimpleCIEventSubscribeWithNoParamOverride() throws Exception {
// Job parameters are NOT overridden when the subscribe build step is used.
FreeStyleProject jobA = j.createFreeStyleProject();
jobA.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("PARAMETER", "original parameter value", "")));
jobA.getBuildersList().add(new CIMessageSubscriberBuilder(getSubscriberProviderData(null, "MESSAGE_CONTENT", "CI_TYPE = 'code-quality-checks-done'")));
jobA.getBuildersList().add(new Shell("echo $PARAMETER"));
jobA.getBuildersList().add(new Shell("echo $MESSAGE_CONTENT"));
scheduleAwaitStep(jobA);
FreeStyleProject jobB = j.createFreeStyleProject();
jobB.getPublishersList().add(new CIMessageNotifier(getPublisherProviderData(null, MessageUtils.MESSAGE_TYPE.CodeQualityChecksDone, "PARAMETER = my parameter", "This is my content")));
j.buildAndAssertSuccess(jobB);
waitUntilScheduledBuildCompletes();
j.assertBuildStatusSuccess(jobA.getLastBuild());
j.assertLogContains("original parameter value", jobA.getLastBuild());
j.assertLogContains("This is my content", jobA.getLastBuild());
}
use of hudson.model.StringParameterDefinition in project jms-messaging-plugin by jenkinsci.
the class SharedMessagingPluginIntegrationTest method _testSimpleCIEventSubscribeWithTopicOverrideAndVariableTopic.
public void _testSimpleCIEventSubscribeWithTopicOverrideAndVariableTopic() throws Exception {
FreeStyleProject jobA = j.createFreeStyleProject();
jobA.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("MY_TOPIC", "my-topic", "")));
jobA.getBuildersList().add(new CIMessageSubscriberBuilder(getSubscriberProviderData("$MY_TOPIC", "HELLO", "CI_TYPE = 'code-quality-checks-done'")));
jobA.getBuildersList().add(new Shell("echo $HELLO"));
scheduleAwaitStep(jobA);
FreeStyleProject jobB = j.createFreeStyleProject();
jobB.getPublishersList().add(new CIMessageNotifier(getPublisherProviderData("my-topic", MessageUtils.MESSAGE_TYPE.CodeQualityChecksDone, "CI_STATUS = failed", "Hello World")));
j.buildAndAssertSuccess(jobB);
waitUntilScheduledBuildCompletes();
j.assertBuildStatusSuccess(jobA.getLastBuild());
j.assertLogContains("Hello World", jobA.getLastBuild());
}
Aggregations