Search in sources :

Example 36 with StringParameterDefinition

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);
    }
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) MockSCMSource(jenkins.scm.impl.mock.MockSCMSource) StringParameterValue(hudson.model.StringParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) ParametersAction(hudson.model.ParametersAction) MockSCMDiscoverBranches(jenkins.scm.impl.mock.MockSCMDiscoverBranches) Cause(hudson.model.Cause) MockSCMController(jenkins.scm.impl.mock.MockSCMController) BasicMultiBranchProject(integration.harness.BasicMultiBranchProject) Test(org.junit.Test)

Example 37 with StringParameterDefinition

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;
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) BooleanParameterDefinition(hudson.model.BooleanParameterDefinition) TextParameterValue(hudson.model.TextParameterValue) StringParameterValue(hudson.model.StringParameterValue) ParameterValue(hudson.model.ParameterValue) BooleanParameterValue(hudson.model.BooleanParameterValue) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) BooleanParameterValue(hudson.model.BooleanParameterValue) ArrayList(java.util.ArrayList) StringParameterValue(hudson.model.StringParameterValue) TextParameterDefinition(hudson.model.TextParameterDefinition) TextParameterValue(hudson.model.TextParameterValue) ChoiceParameterDefinition(hudson.model.ChoiceParameterDefinition) ChoiceParameterDefinition(hudson.model.ChoiceParameterDefinition) StringParameterDefinition(hudson.model.StringParameterDefinition) TextParameterDefinition(hudson.model.TextParameterDefinition) ParameterDefinition(hudson.model.ParameterDefinition) BooleanParameterDefinition(hudson.model.BooleanParameterDefinition)

Example 38 with StringParameterDefinition

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());
}
Also used : Shell(hudson.tasks.Shell) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) CIMessageNotifier(com.redhat.jenkins.plugins.ci.CIMessageNotifier) CIBuildTrigger(com.redhat.jenkins.plugins.ci.CIBuildTrigger) FreeStyleProject(hudson.model.FreeStyleProject) MsgCheck(com.redhat.jenkins.plugins.ci.messaging.checks.MsgCheck)

Example 39 with StringParameterDefinition

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());
}
Also used : Shell(hudson.tasks.Shell) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) CIMessageNotifier(com.redhat.jenkins.plugins.ci.CIMessageNotifier) CIMessageSubscriberBuilder(com.redhat.jenkins.plugins.ci.CIMessageSubscriberBuilder) FreeStyleProject(hudson.model.FreeStyleProject)

Example 40 with StringParameterDefinition

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());
}
Also used : Shell(hudson.tasks.Shell) StringParameterDefinition(hudson.model.StringParameterDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) CIMessageNotifier(com.redhat.jenkins.plugins.ci.CIMessageNotifier) CIMessageSubscriberBuilder(com.redhat.jenkins.plugins.ci.CIMessageSubscriberBuilder) FreeStyleProject(hudson.model.FreeStyleProject)

Aggregations

StringParameterDefinition (hudson.model.StringParameterDefinition)95 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)82 Test (org.junit.Test)77 FreeStyleProject (hudson.model.FreeStyleProject)69 ParametersAction (hudson.model.ParametersAction)45 StringParameterValue (hudson.model.StringParameterValue)44 FreeStyleBuild (hudson.model.FreeStyleBuild)43 Issue (org.jvnet.hudson.test.Issue)26 ParameterDefinition (hudson.model.ParameterDefinition)24 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)16 FileWriteBuilder (hudson.plugins.copyartifact.testutils.FileWriteBuilder)15 ArtifactArchiver (hudson.tasks.ArtifactArchiver)15 Shell (hudson.tasks.Shell)15 Cause (hudson.model.Cause)12 ArrayList (java.util.ArrayList)11 CIMessageNotifier (com.redhat.jenkins.plugins.ci.CIMessageNotifier)10 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)10 BooleanParameterDefinition (hudson.model.BooleanParameterDefinition)9 PromotionProcess (hudson.plugins.promoted_builds.PromotionProcess)9 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)9