use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.
the class OrganizationFolderTest method testOrganizationFolderFactoryNoPermissionsFolder.
@Test(expected = ServiceException.ForbiddenException.class)
public void testOrganizationFolderFactoryNoPermissionsFolder() throws Exception {
List<OrganizationFolderPipelineImpl.OrganizationFolderFactory> organizationFolderFactoryList = ExtensionList.lookup(OrganizationFolderPipelineImpl.OrganizationFolderFactory.class);
OrganizationFolderFactoryTestImpl organizationFolderFactoryTest = ((ExtensionList<OrganizationFolderPipelineImpl.OrganizationFolderFactory>) organizationFolderFactoryList).get(OrganizationFolderFactoryTestImpl.class);
assertNotNull(organizationFolderFactoryTest);
OrganizationFolderPipelineImpl folderPipeline = organizationFolderFactoryTest.getFolder(orgFolder, new Reachable() {
@Override
public Link getLink() {
return organization.getLink().rel("/pipelines/");
}
}, mockOrganization());
assertNotNull(folderPipeline);
assertNotNull(folderPipeline.getQueue());
assertNotNull(folderPipeline.getQueue().iterator());
// Make sure the user does not have permissions to that folder
PowerMockito.when(orgFolder.getACL()).thenReturn(new ACL() {
@Override
public boolean hasPermission(Authentication arg0, Permission arg1) {
return false;
}
});
ScmResourceImpl scmResource = new ScmResourceImpl(orgFolder, folderPipeline);
StaplerRequest staplerRequest = PowerMockito.mock(StaplerRequest.class);
assertEquals("hello", scmResource.getContent(staplerRequest));
}
use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.
the class PipelinePluginAnalytics method onCompleted.
@Override
public void onCompleted(WorkflowRun workflowRun, @Nonnull TaskListener listener) {
Analytics analytics = Analytics.get();
if (analytics == null) {
return;
}
// Tally up all the steps used in this run
Tally tally = new Tally();
NodeGraphBuilder builder = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(workflowRun);
builder.getPipelineNodeSteps(new Link("steps/")).forEach(step -> tally.count(step.getStepType()));
boolean isDeclarative = workflowRun.getParent().getAction(DeclarativeJobAction.class) != null;
Result result = workflowRun.getResult();
String resultAsString = result != null ? result.toString() : "UNKNOWN";
// Send event for each step used in this run
tally.get().forEach((key, value) -> {
Map<String, Object> props = new HashMap<>();
props.put("type", key);
props.put("timesUsed", value);
props.put("isDeclarative", isDeclarative);
props.put("runResult", resultAsString);
analytics.track(new TrackRequest("pipeline_step_used", props));
});
}
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());
}
use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.
the class BranchContainerImpl method iterator.
@Override
@SuppressWarnings("unchecked")
public Iterator<BluePipeline> iterator(int start, int limit) {
final BlueOrganization organization = OrganizationFactory.getInstance().getContainingOrg(pipeline.mbp.getItemGroup());
if (organization == null) {
throw new ServiceException.UnexpectedErrorException("Could not find organization for " + pipeline.mbp.getFullName());
}
final Link link = getLink();
// Filter will decide if the requester wants branches or pull requests
Collection<Job> allJobsMatchinFilter = ContainerFilter.filter(pipeline.mbp.getAllJobs());
return allJobsMatchinFilter.stream().map(job -> (BluePipeline) new BranchImpl(organization, job, link)).sorted(BRANCH_COMPARATOR).skip(start).limit(limit).iterator();
}
use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.
the class ArtifactImplTest method findUniqueArtifactsWithSameName.
@Test
public void findUniqueArtifactsWithSameName() throws IllegalAccessException {
// mock artifacts
Run.Artifact artifact1 = mock(Run.Artifact.class);
Run.Artifact artifact2 = mock(Run.Artifact.class);
// artifact1 mocks
when(artifact1.getFileName()).thenReturn("test-suite.log");
MemberModifier.field(Run.Artifact.class, "relativePath").set(artifact1, "path1/test-suite.log");
when(artifact1.getHref()).thenReturn("path1/test-suite.log");
// artifact2 mocks
when(artifact2.getFileName()).thenReturn("test-suite.log");
MemberModifier.field(Run.Artifact.class, "relativePath").set(artifact2, "path2/test-suite.log");
when(artifact2.getHref()).thenReturn("path2/test-suite.log");
// list of artifacts
ArrayList artifactList = new ArrayList();
artifactList.add(artifact1);
artifactList.add(artifact2);
// mock run
Run run = mock(Run.class);
when(run.getUrl()).thenReturn("job/myfolder/job/myjob/1/");
when(run.getArtifacts()).thenReturn(artifactList);
Link parentLink = mock(Link.class);
ArtifactImpl a1 = new ArtifactImpl(run, artifact1, parentLink);
ArtifactImpl a2 = new ArtifactImpl(run, artifact2, parentLink);
assertThat(a1.getId(), is(not(a2.getId())));
}
Aggregations