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());
}
}
}
}
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());
}
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());
}
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;
}
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());
}
Aggregations