Search in sources :

Example 86 with StringParameterDefinition

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

Example 87 with StringParameterDefinition

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

Example 88 with StringParameterDefinition

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();
    }
}
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) MockSCMController(jenkins.scm.impl.mock.MockSCMController) BasicMultiBranchProject(integration.harness.BasicMultiBranchProject) Test(org.junit.Test)

Example 89 with StringParameterDefinition

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

Example 90 with StringParameterDefinition

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

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