Search in sources :

Example 16 with CIBuildTrigger

use of com.redhat.jenkins.plugins.ci.CIBuildTrigger in project jms-messaging-plugin by jenkinsci.

the class SharedMessagingPluginIntegrationTest method _testSimpleCIEventTriggerOnPipelineJob.

public void _testSimpleCIEventTriggerOnPipelineJob() throws Exception {
    WorkflowJob jobA = j.jenkins.createProject(WorkflowJob.class, "jobA");
    jobA.setDefinition(new CpsFlowDefinition("node('master') {\n sleep 10\n}", true));
    attachTrigger(new CIBuildTrigger(false, Collections.singletonList(getSubscriberProviderData(null, null, "CI_TYPE = 'code-quality-checks-done' and CI_STATUS = 'failed'"))), jobA);
    FreeStyleProject jobB = j.createFreeStyleProject();
    jobB.getPublishersList().add(new CIMessageNotifier(getPublisherProviderData(null, MessageUtils.MESSAGE_TYPE.CodeQualityChecksDone, "CI_STATUS = failed", "Hello World")));
    j.buildAndAssertSuccess(jobB);
    waitUntilScheduledBuildCompletes();
    j.assertBuildStatusSuccess(jobA.getLastBuild());
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) CIMessageNotifier(com.redhat.jenkins.plugins.ci.CIMessageNotifier) CIBuildTrigger(com.redhat.jenkins.plugins.ci.CIBuildTrigger) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) FreeStyleProject(hudson.model.FreeStyleProject)

Example 17 with CIBuildTrigger

use of com.redhat.jenkins.plugins.ci.CIBuildTrigger in project jms-messaging-plugin by jenkinsci.

the class SharedMessagingPluginIntegrationTest method _testVerifyModelUIPersistence.

public void _testVerifyModelUIPersistence() throws Exception {
    WorkflowJob jobA = j.jenkins.createProject(WorkflowJob.class, "jobA");
    jobA.setDefinition(new CpsFlowDefinition("node('master') {\n echo 'hello world' \n} ", true));
    CIBuildTrigger trigger = new CIBuildTrigger(true, Collections.singletonList(getSubscriberProviderData("otopic", "HELLO", null, new MsgCheck(MESSAGE_CHECK_FIELD, MESSAGE_CHECK_VALUE))));
    attachTrigger(trigger, jobA);
    j.configRoundtrip(jobA);
    CIBuildTrigger ciTrigger = jobA.getTriggers().values().stream().filter(t -> t instanceof CIBuildTrigger).map(t -> (CIBuildTrigger) t).findFirst().get();
    assertThat(ciTrigger, equalTo(trigger));
    WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, "job");
    job.setDefinition(new CpsFlowDefinition("node('master') {\n def message = sendCIMessage " + " providerName: '" + DEFAULT_PROVIDER_NAME + "', " + " overrides: [topic: 'otopic'], " + " failOnError: true, " + " messageContent: '" + MESSAGE_CHECK_CONTENT + "'}\n", true));
    j.buildAndAssertSuccess(job);
    waitUntilScheduledBuildCompletes();
    j.assertBuildStatusSuccess(jobA.getLastBuild());
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) CIMessageNotifier(com.redhat.jenkins.plugins.ci.CIMessageNotifier) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) Arrays(java.util.Arrays) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) FreeStyleProject(hudson.model.FreeStyleProject) StringParameterValue(hudson.model.StringParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) MessagingProviderOverrides(com.redhat.jenkins.plugins.ci.messaging.MessagingProviderOverrides) Charset(java.nio.charset.Charset) CIMessageBuilder(com.redhat.jenkins.plugins.ci.CIMessageBuilder) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) MessageUtils(com.redhat.utils.MessageUtils) Docker(org.jenkinsci.test.acceptance.docker.Docker) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) BooleanParameterDefinition(hudson.model.BooleanParameterDefinition) StringWriter(java.io.StringWriter) CIMessageSubscriberBuilder(com.redhat.jenkins.plugins.ci.CIMessageSubscriberBuilder) EnvironmentVariablesNodeProperty(hudson.slaves.EnvironmentVariablesNodeProperty) Matchers(org.hamcrest.Matchers) MsgCheck(com.redhat.jenkins.plugins.ci.messaging.checks.MsgCheck) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Shell(hudson.tasks.Shell) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) CIBuildTrigger(com.redhat.jenkins.plugins.ci.CIBuildTrigger) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) Rule(org.junit.Rule) AbstractProject(hudson.model.AbstractProject) ParametersAction(hudson.model.ParametersAction) Result(hudson.model.Result) Job(hudson.model.Job) StringParameterDefinition(hudson.model.StringParameterDefinition) Pattern(java.util.regex.Pattern) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) ProviderData(com.redhat.jenkins.plugins.ci.provider.data.ProviderData) Collections(java.util.Collections) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) DockerContainer(org.jenkinsci.test.acceptance.docker.DockerContainer) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) CIBuildTrigger(com.redhat.jenkins.plugins.ci.CIBuildTrigger) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) MsgCheck(com.redhat.jenkins.plugins.ci.messaging.checks.MsgCheck)

Example 18 with CIBuildTrigger

use of com.redhat.jenkins.plugins.ci.CIBuildTrigger in project jms-messaging-plugin by jenkinsci.

the class SharedMessagingPluginIntegrationTest method _testSimpleCIEventTriggerWithChoiceParam.

public void _testSimpleCIEventTriggerWithChoiceParam(String properties, String body, String matchString) throws Exception {
    WorkflowJob jobA = j.jenkins.createProject(WorkflowJob.class, "foo");
    jobA.setDefinition(new CpsFlowDefinition("node('master') {\n echo \"mychoice is $mychoice\"\n}", true));
    jobA.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("CI_MESSAGE", "", ""), new StringParameterDefinition("mychoice", "scott\ntom", "")));
    attachTrigger(new CIBuildTrigger(false, Collections.singletonList(getSubscriberProviderData(null, null, null))), jobA);
    FreeStyleProject jobB = j.createFreeStyleProject();
    jobB.getPublishersList().add(new CIMessageNotifier(getPublisherProviderData(null, null, properties, body)));
    j.buildAndAssertSuccess(jobB);
    waitUntilScheduledBuildCompletes();
    j.assertBuildStatusSuccess(jobA.getLastBuild());
    j.assertLogContains(matchString, jobA.getLastBuild());
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) CIMessageNotifier(com.redhat.jenkins.plugins.ci.CIMessageNotifier) CIBuildTrigger(com.redhat.jenkins.plugins.ci.CIBuildTrigger) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) FreeStyleProject(hudson.model.FreeStyleProject)

Example 19 with CIBuildTrigger

use of com.redhat.jenkins.plugins.ci.CIBuildTrigger in project jms-messaging-plugin by jenkinsci.

the class SharedMessagingPluginIntegrationTest method _testSimpleCIEventTriggerWithTextArea.

public void _testSimpleCIEventTriggerWithTextArea(String body, String matchString) throws Exception {
    FreeStyleProject jobA = j.createFreeStyleProject();
    jobA.getBuildersList().add(new Shell("echo CI_MESSAGE = \"$CI_MESSAGE\""));
    jobA.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("CI_MESSAGE", "", "")));
    attachTrigger(new CIBuildTrigger(false, Collections.singletonList(getSubscriberProviderData(null, null, null))), jobA);
    FreeStyleProject jobB = j.createFreeStyleProject();
    jobB.getPublishersList().add(new CIMessageNotifier(getPublisherProviderData(null, null, null, body)));
    j.buildAndAssertSuccess(jobB);
    waitUntilScheduledBuildCompletes();
    j.assertBuildStatusSuccess(jobA.getLastBuild());
    j.assertLogContains(matchString, 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)

Example 20 with CIBuildTrigger

use of com.redhat.jenkins.plugins.ci.CIBuildTrigger in project jms-messaging-plugin by jenkinsci.

the class SharedMessagingPluginIntegrationTest method _testDisabledWorkflowJobDoesNotGetTriggered.

public void _testDisabledWorkflowJobDoesNotGetTriggered() throws Exception {
    WorkflowJob jobA = j.jenkins.createProject(WorkflowJob.class, "jobA");
    jobA.setDefinition(new CpsFlowDefinition("echo \"CI_TYPE = ${env.CI_TYPE}\"", true));
    attachTrigger(new CIBuildTrigger(false, Collections.singletonList(getSubscriberProviderData(null, null, "CI_TYPE = 'code-quality-checks-done' and CI_STATUS = 'failed'"))), jobA);
    jobA.doDisable();
    FreeStyleProject jobB = j.createFreeStyleProject();
    jobB.getPublishersList().add(new CIMessageNotifier(getPublisherProviderData(null, MessageUtils.MESSAGE_TYPE.CodeQualityChecksDone, "CI_STATUS = failed", null)));
    j.buildAndAssertSuccess(jobB);
    Thread.sleep(5000);
    assertThat(jobA.getBuilds(), Matchers.iterableWithSize(0));
    jobA.doEnable();
    Thread.sleep(3000);
    j.buildAndAssertSuccess(jobB);
    waitUntilScheduledBuildCompletes();
    j.assertBuildStatusSuccess(jobA.getLastBuild());
    j.assertLogContains("CI_TYPE = code-quality-checks-done", jobA.getLastBuild());
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) CIMessageNotifier(com.redhat.jenkins.plugins.ci.CIMessageNotifier) CIBuildTrigger(com.redhat.jenkins.plugins.ci.CIBuildTrigger) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) FreeStyleProject(hudson.model.FreeStyleProject)

Aggregations

CIBuildTrigger (com.redhat.jenkins.plugins.ci.CIBuildTrigger)35 FreeStyleProject (hudson.model.FreeStyleProject)34 Shell (hudson.tasks.Shell)26 CIMessageNotifier (com.redhat.jenkins.plugins.ci.CIMessageNotifier)24 MsgCheck (com.redhat.jenkins.plugins.ci.messaging.checks.MsgCheck)14 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)10 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)10 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)9 StringParameterDefinition (hudson.model.StringParameterDefinition)8 FreeStyleBuild (hudson.model.FreeStyleBuild)6 Test (org.junit.Test)6 CIMessageBuilder (com.redhat.jenkins.plugins.ci.CIMessageBuilder)3 ActiveMQSubscriberProviderData (com.redhat.jenkins.plugins.ci.provider.data.ActiveMQSubscriberProviderData)3 EnvironmentVariablesNodeProperty (hudson.slaves.EnvironmentVariablesNodeProperty)3 FedmsgRelayContainer (com.redhat.jenkins.plugins.ci.integration.fixtures.FedmsgRelayContainer)2 MessagingProviderOverrides (com.redhat.jenkins.plugins.ci.messaging.MessagingProviderOverrides)2 BooleanParameterDefinition (hudson.model.BooleanParameterDefinition)2 ParametersAction (hudson.model.ParametersAction)2 StringParameterValue (hudson.model.StringParameterValue)2 File (java.io.File)2