Search in sources :

Example 1 with TextParameterDefinition

use of hudson.model.TextParameterDefinition in project jms-messaging-plugin by jenkinsci.

the class AmqMessagingPluginIntegrationTest method testSimpleCIEventWithMessagePropertiesAsVariable.

@Test
public void testSimpleCIEventWithMessagePropertiesAsVariable() throws Exception {
    FreeStyleProject jobA = j.createFreeStyleProject();
    jobA.getBuildersList().add(new Shell("echo CI_TYPE = $CI_TYPE"));
    jobA.getBuildersList().add(new Shell("echo TEST_PROP1 = $TEST_PROP1"));
    jobA.getBuildersList().add(new Shell("echo TEST_PROP2 = $TEST_PROP2"));
    attachTrigger(new CIBuildTrigger(true, Collections.singletonList(getSubscriberProviderData("otopic", "CI_MESSAGE", "CI_TYPE = 'code-quality-checks-done' and CI_STATUS = 'failed'"))), jobA);
    Thread.sleep(1000);
    FreeStyleProject jobB = j.createFreeStyleProject();
    jobB.addProperty(new ParametersDefinitionProperty(new TextParameterDefinition("MESSAGE_PROPERTIES", "CI_STATUS = failed\nTEST_PROP1 = GOT 1\nTEST_PROP2 = GOT 2", "")));
    jobB.getBuildersList().add(new CIMessageBuilder(getPublisherProviderData("otopic", MessageUtils.MESSAGE_TYPE.CodeQualityChecksDone, "${MESSAGE_PROPERTIES}", "")));
    j.buildAndAssertSuccess(jobB);
    waitUntilScheduledBuildCompletes();
    FreeStyleBuild lastBuild = jobA.getLastBuild();
    j.assertBuildStatusSuccess(lastBuild);
    j.assertLogContains("echo CI_TYPE = code-quality-checks-done", lastBuild);
    j.assertLogContains("echo TEST_PROP1 = GOT 1", lastBuild);
    j.assertLogContains("echo TEST_PROP2 = GOT 2", lastBuild);
}
Also used : Shell(hudson.tasks.Shell) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) CIMessageBuilder(com.redhat.jenkins.plugins.ci.CIMessageBuilder) CIBuildTrigger(com.redhat.jenkins.plugins.ci.CIBuildTrigger) TextParameterDefinition(hudson.model.TextParameterDefinition) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 2 with TextParameterDefinition

use of hudson.model.TextParameterDefinition 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 3 with TextParameterDefinition

use of hudson.model.TextParameterDefinition in project jms-messaging-plugin by jenkinsci.

the class AmqMessagingPluginIntegrationTest method _testPipelineJobProperties.

public void _testPipelineJobProperties(boolean backwardCompatible) throws Exception {
    List<Thread> leftoverFromPreviousRuns = getThreadsByName("ActiveMQ.*Task-.*");
    leftoverFromPreviousRuns.addAll(getThreadsByName("CIBuildTrigger.*"));
    for (Thread thread : leftoverFromPreviousRuns) {
        thread.interrupt();
        thread.stop();
    }
    WorkflowJob send = j.jenkins.createProject(WorkflowJob.class, "send");
    send.setDefinition(new CpsFlowDefinition("node('master') {\n sendCIMessage" + " providerName: '" + DEFAULT_PROVIDER_NAME + "', " + " failOnError: true, " + " messageContent: '" + MESSAGE_CHECK_CONTENT + "', " + " messageProperties: 'CI_STATUS2 = ${CI_STATUS2}', " + " messageType: 'CodeQualityChecksDone'}", true));
    // [expectedValue: number + '0.0234', field: 'CI_STATUS2']
    String pd = "[$class: 'ActiveMQSubscriberProviderData', name: '" + DEFAULT_PROVIDER_NAME + "', selector: 'CI_NAME = \\'" + send.getName() + "\\'']";
    if (backwardCompatible) {
        pd = "providerData: " + pd;
    } else {
        pd = "providerList: [" + pd + "]";
    }
    WorkflowJob receive = j.jenkins.createProject(WorkflowJob.class, "receive");
    receive.addProperty(new ParametersDefinitionProperty(new TextParameterDefinition("CI_MESSAGE", "", "")));
    receive.setDefinition(new CpsFlowDefinition("def number = currentBuild.getNumber().toString()\n" + "properties(\n" + "    [\n" + "        pipelineTriggers(\n" + "            [[$class: 'CIBuildTrigger', noSquash: false, " + pd + "]]\n" + "        )\n" + "    ]\n" + ")\nnode('master') {\n sleep 1\n}", true));
    j.buildAndAssertSuccess(receive);
    // Allow some time for trigger thread stop/start.
    Thread.sleep(2000);
    assertEquals("ActiveMQ.*Task- count", 1, getCurrentThreadCountForName("ActiveMQ.*Task-.*"));
    assertEquals("CIBuildTrigger count", 1, getCurrentThreadCountForName("CIBuildTrigger.*"));
    j.configRoundtrip(receive);
    j.buildAndAssertSuccess(receive);
    Thread.sleep(2000);
    printThreadsWithName("ActiveMQ.*Task-.*");
    printThreadsWithName("CIBuildTrigger.*");
    assertEquals("ActiveMQ.*Task- count", 1, getCurrentThreadCountForName("ActiveMQ.*Task-.*"));
    assertEquals("CIBuildTrigger count", 1, getCurrentThreadCountForName("CIBuildTrigger.*"));
    // checks: [[expectedValue: '0.0234', field: 'CI_STATUS2']]
    String randomNumber = "123456789";
    for (int i = 0; i < 3; i++) {
        QueueTaskFuture<WorkflowRun> build = send.scheduleBuild2(0, new ParametersAction(new TextParameterValue("CI_STATUS2", randomNumber, "")));
        j.assertBuildStatusSuccess(build);
    }
    Thread.sleep(5000);
    assertEquals("there are not 5 builds", 5, receive.getLastBuild().getNumber());
    printThreadsWithName("ActiveMQ.*Task-.*");
    printThreadsWithName("CIBuildTrigger.*");
    assertEquals("ActiveMQ.*Task- count", 1, getCurrentThreadCountForName("ActiveMQ.*Task-.*"));
    assertEquals("CIBuildTrigger count", 1, getCurrentThreadCountForName("CIBuildTrigger.*"));
    pd = "[$class: 'ActiveMQSubscriberProviderData', checks: [[field: '" + MESSAGE_CHECK_FIELD + "', expectedValue: '" + MESSAGE_CHECK_VALUE + "']], name: 'test', selector: 'CI_NAME = \\'" + send.getName() + "\\'']";
    if (backwardCompatible) {
        pd = "providerData: " + pd;
    } else {
        pd = "providerList: [" + pd + "]";
    }
    receive.setDefinition(new CpsFlowDefinition("def number = currentBuild.getNumber().toString()\n" + "properties(\n" + "    [\n" + "        pipelineTriggers(\n" + "            [[$class: 'CIBuildTrigger', noSquash: false, " + pd + "]]\n" + "        )\n" + "    ]\n" + ")\nnode('master') {\n sleep 1\n}", false));
    scheduleAwaitStep(receive);
    for (int i = 0; i < 3; i++) {
        QueueTaskFuture<WorkflowRun> build = send.scheduleBuild2(0, new ParametersAction(new TextParameterValue("CI_STATUS2", randomNumber, "")));
        j.assertBuildStatusSuccess(build);
        Thread.sleep(1000);
    }
    Thread.sleep(2000);
    assertEquals("there are not 9 builds", 9, receive.getLastBuild().getNumber());
    for (int i = 1; i < 8; i++) {
        j.assertBuildStatusSuccess(receive.getBuildByNumber(i));
    }
    printThreadsWithName("ActiveMQ.*Task-.*");
    printThreadsWithName("CIBuildTrigger.*");
    assertEquals("ActiveMQ.*Task- count", 1, getCurrentThreadCountForName("ActiveMQ.*Task-.*"));
    assertEquals("CIBuildTrigger count", 1, getCurrentThreadCountForName("CIBuildTrigger.*"));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) TextParameterDefinition(hudson.model.TextParameterDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) ParametersAction(hudson.model.ParametersAction) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) TextParameterValue(hudson.model.TextParameterValue)

Aggregations

ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)3 TextParameterDefinition (hudson.model.TextParameterDefinition)3 TextParameterValue (hudson.model.TextParameterValue)2 CIBuildTrigger (com.redhat.jenkins.plugins.ci.CIBuildTrigger)1 CIMessageBuilder (com.redhat.jenkins.plugins.ci.CIMessageBuilder)1 BooleanParameterDefinition (hudson.model.BooleanParameterDefinition)1 BooleanParameterValue (hudson.model.BooleanParameterValue)1 ChoiceParameterDefinition (hudson.model.ChoiceParameterDefinition)1 FreeStyleBuild (hudson.model.FreeStyleBuild)1 FreeStyleProject (hudson.model.FreeStyleProject)1 ParameterDefinition (hudson.model.ParameterDefinition)1 ParameterValue (hudson.model.ParameterValue)1 ParametersAction (hudson.model.ParametersAction)1 StringParameterDefinition (hudson.model.StringParameterDefinition)1 StringParameterValue (hudson.model.StringParameterValue)1 Shell (hudson.tasks.Shell)1 ArrayList (java.util.ArrayList)1 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)1 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)1 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)1