Search in sources :

Example 1 with CIMessageBuilder

use of com.redhat.jenkins.plugins.ci.CIMessageBuilder 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 CIMessageBuilder

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

the class SharedMessagingPluginIntegrationTest method _testSimpleCIEventTriggerWithMultipleTopics.

// TODO restart tests
public void _testSimpleCIEventTriggerWithMultipleTopics() throws Exception {
    FreeStyleProject jobA = j.createFreeStyleProject();
    attachTrigger(new CIBuildTrigger(false, Arrays.asList(getSubscriberProviderData("topic1", null, null, new MsgCheck("my-topic", "topic1")), getSubscriberProviderData("topic2", null, null, new MsgCheck("my-topic", "topic2")))), jobA);
    jobA.getBuildersList().add(new Shell("echo $CI_MESSAGE"));
    FreeStyleProject jobB = j.createFreeStyleProject();
    jobB.getBuildersList().add(new CIMessageBuilder(getPublisherProviderData("topic1", MessageUtils.MESSAGE_TYPE.CodeQualityChecksDone, null, "{ \"my-topic\" : \"topic1\" }")));
    j.buildAndAssertSuccess(jobB);
    waitUntilScheduledBuildCompletes();
    j.assertBuildStatusSuccess(jobA.getLastBuild());
    j.assertLogContains("topic1", jobA.getLastBuild());
    FreeStyleProject jobC = j.createFreeStyleProject();
    jobC.getBuildersList().add(new CIMessageBuilder(getPublisherProviderData("topic2", MessageUtils.MESSAGE_TYPE.CodeQualityChecksDone, null, "{ \"my-topic\" : \"topic2\" }")));
    j.buildAndAssertSuccess(jobC);
    waitUntilScheduledBuildCompletes();
    j.assertBuildStatusSuccess(jobA.getLastBuild());
    j.assertLogContains("topic2", jobA.getLastBuild());
}
Also used : Shell(hudson.tasks.Shell) CIMessageBuilder(com.redhat.jenkins.plugins.ci.CIMessageBuilder) CIBuildTrigger(com.redhat.jenkins.plugins.ci.CIBuildTrigger) FreeStyleProject(hudson.model.FreeStyleProject) MsgCheck(com.redhat.jenkins.plugins.ci.messaging.checks.MsgCheck)

Example 3 with CIMessageBuilder

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

the class SharedMessagingPluginIntegrationTest method _testEnsureFailedSendingOfMessageFailsBuild.

public void _testEnsureFailedSendingOfMessageFailsBuild() throws Exception {
    FreeStyleProject jobB = j.createFreeStyleProject();
    jobB.getBuildersList().add(new CIMessageBuilder(getPublisherProviderData(null, MessageUtils.MESSAGE_TYPE.CodeQualityChecksDone, "CI_STATUS = failed", null)));
    FreeStyleBuild build = j.buildAndAssertStatus(Result.FAILURE, jobB);
    j.assertLogContains("Unhandled exception in perform: ", build);
}
Also used : CIMessageBuilder(com.redhat.jenkins.plugins.ci.CIMessageBuilder) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject)

Example 4 with CIMessageBuilder

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

the class MessageProviderMigrator method migrateCIMessageBuilders.

@Initializer(after = InitMilestone.JOB_LOADED)
public static void migrateCIMessageBuilders() {
    Jenkins instance = Jenkins.get();
    if (GlobalCIConfiguration.get().isMigrationInProgress()) {
        log.info("isMigrationInProgress - > true | Forcing GlobalCIConfiguration.save()");
        GlobalCIConfiguration.get().save();
    }
    int updatedCount = 0;
    log.info("Attempting to migrate all CIMessageBuilders, CIMessageNotifier and CIMessageSubscriberBuilders build/publish steps");
    for (BuildableItemWithBuildWrappers item : instance.getItems(BuildableItemWithBuildWrappers.class)) {
        Job<?, ?> job = (Job<?, ?>) item;
        if (job instanceof Project) {
            Project<?, ?> p = (Project<?, ?>) item.asProject();
            for (CIMessageBuilder builderObj : p.getBuildersList().getAll(CIMessageBuilder.class)) {
                if (updateCIMessageBuilder(p, builderObj)) {
                    updatedCount++;
                }
            }
            for (CIMessageNotifier notifierObj : p.getPublishersList().getAll(CIMessageNotifier.class)) {
                if (updateCIMessageNotifier(p, notifierObj)) {
                    updatedCount++;
                }
            }
            for (CIMessageSubscriberBuilder builderObj : p.getBuildersList().getAll(CIMessageSubscriberBuilder.class)) {
                if (updateCIMessageSubscriberBuilder(p, builderObj)) {
                    updatedCount++;
                }
            }
        }
        if (job instanceof MatrixProject) {
            MatrixProject p = (MatrixProject) item.asProject();
            for (CIMessageBuilder builderObj : p.getBuildersList().getAll(CIMessageBuilder.class)) {
                if (updateCIMessageBuilder(p, builderObj)) {
                    updatedCount++;
                }
            }
            for (CIMessageNotifier notifierObj : p.getPublishersList().getAll(CIMessageNotifier.class)) {
                if (updateCIMessageNotifier(p, notifierObj)) {
                    updatedCount++;
                }
            }
            for (CIMessageSubscriberBuilder builderObj : p.getBuildersList().getAll(CIMessageSubscriberBuilder.class)) {
                if (updateCIMessageSubscriberBuilder(p, builderObj)) {
                    updatedCount++;
                }
            }
        }
    }
    log.info("Updated " + updatedCount + " build/publish step(s)");
}
Also used : Jenkins(jenkins.model.Jenkins) MatrixProject(hudson.matrix.MatrixProject) Project(hudson.model.Project) AbstractProject(hudson.model.AbstractProject) CIMessageBuilder(com.redhat.jenkins.plugins.ci.CIMessageBuilder) CIMessageNotifier(com.redhat.jenkins.plugins.ci.CIMessageNotifier) BuildableItemWithBuildWrappers(hudson.model.BuildableItemWithBuildWrappers) CIMessageSubscriberBuilder(com.redhat.jenkins.plugins.ci.CIMessageSubscriberBuilder) Job(hudson.model.Job) MatrixProject(hudson.matrix.MatrixProject) Initializer(hudson.init.Initializer)

Aggregations

CIMessageBuilder (com.redhat.jenkins.plugins.ci.CIMessageBuilder)4 FreeStyleProject (hudson.model.FreeStyleProject)3 CIBuildTrigger (com.redhat.jenkins.plugins.ci.CIBuildTrigger)2 FreeStyleBuild (hudson.model.FreeStyleBuild)2 Shell (hudson.tasks.Shell)2 CIMessageNotifier (com.redhat.jenkins.plugins.ci.CIMessageNotifier)1 CIMessageSubscriberBuilder (com.redhat.jenkins.plugins.ci.CIMessageSubscriberBuilder)1 MsgCheck (com.redhat.jenkins.plugins.ci.messaging.checks.MsgCheck)1 Initializer (hudson.init.Initializer)1 MatrixProject (hudson.matrix.MatrixProject)1 AbstractProject (hudson.model.AbstractProject)1 BuildableItemWithBuildWrappers (hudson.model.BuildableItemWithBuildWrappers)1 Job (hudson.model.Job)1 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)1 Project (hudson.model.Project)1 TextParameterDefinition (hudson.model.TextParameterDefinition)1 Jenkins (jenkins.model.Jenkins)1 Test (org.junit.Test)1