Search in sources :

Example 1 with JobChannelMessage

use of org.jenkinsci.plugins.pubsub.JobChannelMessage in project blueocean-plugin by jenkinsci.

the class BlueMessageEnricher method enrich.

@Override
public void enrich(@Nonnull Message message) {
    // TODO: Get organization name in generic way once multi-organization support is implemented in API
    message.set(EventProps.Jenkins.jenkins_org, OrganizationImpl.INSTANCE.getName());
    String channelName = message.getChannelName();
    if (channelName.equals(Events.JobChannel.NAME)) {
        JobChannelMessage jobChannelMessage = (JobChannelMessage) message;
        Item jobChannelItem = jobChannelMessage.getJobChannelItem();
        Link jobUrl = LinkResolver.resolveLink(jobChannelItem);
        jobChannelMessage.set(BlueEventProps.blueocean_job_rest_url, jobUrl.getHref());
        jobChannelMessage.set(BlueEventProps.blueocean_job_pipeline_name, jobChannelItem.getFullName());
        if (jobChannelItem instanceof WorkflowJob) {
            ItemGroup<? extends Item> parent = jobChannelItem.getParent();
            if (parent instanceof WorkflowMultiBranchProject) {
                String multiBranchProjectName = parent.getFullName();
                jobChannelMessage.set(BlueEventProps.blueocean_job_pipeline_name, multiBranchProjectName);
                jobChannelMessage.set(BlueEventProps.blueocean_job_branch_name, jobChannelItem.getName());
            }
        }
    }
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) Item(hudson.model.Item) JobChannelMessage(org.jenkinsci.plugins.pubsub.JobChannelMessage) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Link(io.jenkins.blueocean.rest.hal.Link)

Example 2 with JobChannelMessage

use of org.jenkinsci.plugins.pubsub.JobChannelMessage in project blueocean-plugin by jenkinsci.

the class JobIndexingMessageEnricher method enrich.

@Override
public void enrich(@Nonnull Message message) {
    if (message instanceof JobChannelMessage) {
        JobChannelMessage jobChannelMessage = (JobChannelMessage) message;
        Item jobChannelItem = jobChannelMessage.getJobChannelItem();
        Enum indexingStatus;
        Enum indexingResult;
        if (jobChannelItem instanceof OrganizationFolder) {
            indexingStatus = JobIndexing.EventProps.job_orgfolder_indexing_status;
            indexingResult = JobIndexing.EventProps.job_orgfolder_indexing_result;
        } else if (jobChannelItem instanceof MultiBranchProject) {
            jobChannelMessage.set(EventProps.Job.job_ismultibranch, "true");
            indexingStatus = EventProps.Job.job_multibranch_indexing_status;
            indexingResult = EventProps.Job.job_multibranch_indexing_result;
        } else {
            // don't enrich if not org folder or multibranch
            return;
        }
        if (message instanceof QueueTaskMessage) {
            QueueTaskMessage queueTaskMessage = (QueueTaskMessage) message;
            Queue.Item queueItem = queueTaskMessage.getQueueItem();
            if (queueItem instanceof Queue.LeftItem) {
                Queue.LeftItem leftItem = (Queue.LeftItem) queueItem;
                if (leftItem.isCancelled()) {
                    jobChannelMessage.set(indexingStatus, "COMPLETE");
                    jobChannelMessage.set(indexingResult, "CANCELLED");
                } else {
                    if (message.getEventName().equals(Events.JobChannel.job_run_queue_task_complete.name())) {
                        jobChannelMessage.set(indexingStatus, "COMPLETE");
                        Queue.Executable executable = ((Queue.LeftItem) queueItem).getExecutable();
                        if (executable instanceof BranchIndexing) {
                            BranchIndexing branchIndexing = (BranchIndexing) executable;
                            jobChannelMessage.set(indexingResult, branchIndexing.getResult().toString());
                        } else if (executable instanceof OrganizationFolder.OrganizationScan) {
                            OrganizationFolder.OrganizationScan orgScan = (OrganizationFolder.OrganizationScan) executable;
                            jobChannelMessage.set(indexingResult, orgScan.getResult().toString());
                        }
                    } else {
                        jobChannelMessage.set(indexingStatus, "INDEXING");
                    }
                }
            } else {
                jobChannelMessage.set(indexingStatus, "INDEXING");
            }
        }
    }
}
Also used : JobChannelMessage(org.jenkinsci.plugins.pubsub.JobChannelMessage) OrganizationFolder(jenkins.branch.OrganizationFolder) BranchIndexing(jenkins.branch.MultiBranchProject.BranchIndexing) Item(hudson.model.Item) QueueTaskMessage(org.jenkinsci.plugins.pubsub.QueueTaskMessage) MultiBranchProject(jenkins.branch.MultiBranchProject) Queue(hudson.model.Queue)

Aggregations

Item (hudson.model.Item)2 JobChannelMessage (org.jenkinsci.plugins.pubsub.JobChannelMessage)2 Queue (hudson.model.Queue)1 Link (io.jenkins.blueocean.rest.hal.Link)1 MultiBranchProject (jenkins.branch.MultiBranchProject)1 BranchIndexing (jenkins.branch.MultiBranchProject.BranchIndexing)1 OrganizationFolder (jenkins.branch.OrganizationFolder)1 QueueTaskMessage (org.jenkinsci.plugins.pubsub.QueueTaskMessage)1 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)1 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)1