Search in sources :

Example 1 with Link

use of io.jenkins.blueocean.rest.hal.Link 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 Link

use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method testBranchInfo.

@Test
public void testBranchInfo() {
    Job job = mock(Job.class);
    BranchImpl branch = new BranchImpl(job, new Link("foo"));
    assertNotNull(branch.getBranch());
    assertNull(branch.getBranch().getUrl());
    assertFalse(branch.getBranch().isPrimary());
    ObjectMetadataAction oma = new ObjectMetadataAction("My Branch", "A feature branch", "https://path/to/branch");
    when(job.getAction(ObjectMetadataAction.class)).thenReturn(oma);
    assertEquals("https://path/to/branch", branch.getBranch().getUrl());
    assertFalse(branch.getBranch().isPrimary());
    when(job.getAction(PrimaryInstanceMetadataAction.class)).thenReturn(new PrimaryInstanceMetadataAction());
    assertTrue(branch.getBranch().isPrimary());
}
Also used : ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) PrimaryInstanceMetadataAction(jenkins.scm.api.metadata.PrimaryInstanceMetadataAction) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Job(hudson.model.Job) Link(io.jenkins.blueocean.rest.hal.Link) Test(org.junit.Test)

Example 3 with Link

use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method testGetURL.

@Test
public void testGetURL() {
    Job job = mock(Job.class);
    BranchImpl branch = new BranchImpl(job, new Link("foo"));
    assertNotNull(branch.getBranch());
    assertNull(branch.getBranch().getUrl());
    assertFalse(branch.getBranch().isPrimary());
    ObjectMetadataAction oma = new ObjectMetadataAction("My Branch", "A feature branch", "https://path/to/branch");
    when(job.getAction(ObjectMetadataAction.class)).thenReturn(oma);
    assertEquals("https://path/to/branch", branch.getBranch().getUrl());
}
Also used : ObjectMetadataAction(jenkins.scm.api.metadata.ObjectMetadataAction) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Job(hudson.model.Job) Link(io.jenkins.blueocean.rest.hal.Link) Test(org.junit.Test)

Example 4 with Link

use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.

the class RunSearch method collectRuns.

private static List<BlueRun> collectRuns(Iterator<? extends Run> runIterator, final Link parent, int start, int limit) {
    List<BlueRun> runs = new ArrayList<>();
    // Skip up to the start
    int skipCount = start;
    while (runIterator.hasNext()) {
        if (skipCount > 0) {
            runIterator.next();
            skipCount--;
        } else {
            BlueRun run = BlueRunFactory.getRun(runIterator.next(), new Reachable() {

                @Override
                public Link getLink() {
                    return parent;
                }
            });
            if (run != null) {
                runs.add(run);
            }
        }
        if (runs.size() >= limit) {
            return runs;
        }
    }
    return runs;
}
Also used : BlueRun(io.jenkins.blueocean.rest.model.BlueRun) ArrayList(java.util.ArrayList) Reachable(io.jenkins.blueocean.rest.Reachable) Link(io.jenkins.blueocean.rest.hal.Link)

Example 5 with Link

use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.

the class PipelineNodeGraphVisitor method getPipelineNodeSteps.

@Override
public List<BluePipelineStep> getPipelineNodeSteps(final String nodeId, Link parent) {
    FlowExecution execution = run.getExecution();
    if (execution == null) {
        logger.debug(String.format("Pipeline %s, runid %s  has null execution", run.getParent().getName(), run.getId()));
        return Collections.emptyList();
    }
    DepthFirstScanner depthFirstScanner = new DepthFirstScanner();
    // If blocked scope, get the end node
    FlowNode n = depthFirstScanner.findFirstMatch(execution.getCurrentHeads(), input -> (input != null && input.getId().equals(nodeId) && (PipelineNodeUtil.isStage(input) || PipelineNodeUtil.isParallelBranch(input))));
    if (n == null) {
        // if no node found or the node is not stage or parallel we return empty steps
        return Collections.emptyList();
    }
    PipelineStepVisitor visitor = new PipelineStepVisitor(run, n);
    ForkScanner.visitSimpleChunks(execution.getCurrentHeads(), visitor, new StageChunkFinder());
    return visitor.getSteps().stream().map(node -> new PipelineStepImpl(node, parent)).collect(Collectors.toList());
}
Also used : DepthFirstScanner(org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner) Arrays(java.util.Arrays) InputAction(org.jenkinsci.plugins.workflow.support.steps.input.InputAction) LoggerFactory(org.slf4j.LoggerFactory) LabelAction(org.jenkinsci.plugins.workflow.actions.LabelAction) StringUtils(org.apache.commons.lang3.StringUtils) GenericStatus(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.GenericStatus) MemoryFlowChunk(org.jenkinsci.plugins.workflow.graphanalysis.MemoryFlowChunk) Map(java.util.Map) ExecutionModelAction(org.jenkinsci.plugins.pipeline.modeldefinition.actions.ExecutionModelAction) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) BluePipelineNode(io.jenkins.blueocean.rest.model.BluePipelineNode) Action(hudson.model.Action) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) StepStartNode(org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode) List(java.util.List) PauseAction(org.jenkinsci.plugins.workflow.support.actions.PauseAction) Optional(java.util.Optional) FlowStartNode(org.jenkinsci.plugins.workflow.graph.FlowStartNode) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Link(io.jenkins.blueocean.rest.hal.Link) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) TimingAction(org.jenkinsci.plugins.workflow.actions.TimingAction) HashMap(java.util.HashMap) Stack(java.util.Stack) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) TimingInfo(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.TimingInfo) BlockEndNode(org.jenkinsci.plugins.workflow.graph.BlockEndNode) StandardChunkVisitor(org.jenkinsci.plugins.workflow.graphanalysis.StandardChunkVisitor) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) StageChunkFinder(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.StageChunkFinder) StatusAndTiming(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.StatusAndTiming) BluePipelineStep(io.jenkins.blueocean.rest.model.BluePipelineStep) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) NotExecutedNodeAction(org.jenkinsci.plugins.workflow.actions.NotExecutedNodeAction) IOException(java.io.IOException) ForkScanner(org.jenkinsci.plugins.workflow.graphanalysis.ForkScanner) StepAtomNode(org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode) StepEndNode(org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode) ArrayDeque(java.util.ArrayDeque) Comparator(java.util.Comparator) CheckForNull(javax.annotation.CheckForNull) Collections(java.util.Collections) StageChunkFinder(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.StageChunkFinder) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) DepthFirstScanner(org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode)

Aggregations

Link (io.jenkins.blueocean.rest.hal.Link)30 Test (org.junit.Test)12 BlueRun (io.jenkins.blueocean.rest.model.BlueRun)8 Run (hudson.model.Run)7 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)7 Reachable (io.jenkins.blueocean.rest.Reachable)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 BlueOrganization (io.jenkins.blueocean.rest.model.BlueOrganization)5 BluePipelineNode (io.jenkins.blueocean.rest.model.BluePipelineNode)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)4 Job (hudson.model.Job)3 ServiceException (io.jenkins.blueocean.commons.ServiceException)3 BluePipelineStep (io.jenkins.blueocean.rest.model.BluePipelineStep)3 BlueQueueItem (io.jenkins.blueocean.rest.model.BlueQueueItem)3