use of jenkins.branch.MultiBranchProject in project blueocean-plugin by jenkinsci.
the class GitPipelineUpdateRequest method update.
@CheckForNull
@Override
@SuppressWarnings("unchecked")
public BluePipeline update(BluePipeline pipeline) throws IOException {
Item item = Jenkins.getInstance().getItemByFullName(pipeline.getFullName());
if (item instanceof MultiBranchProject) {
ACL acl = Jenkins.getInstance().getACL();
Authentication a = Jenkins.getAuthentication();
if (!acl.hasPermission(a, Item.CONFIGURE)) {
throw new ServiceException.ForbiddenException(String.format("Failed to update Git pipeline: %s. User %s doesn't have Job configure permission", pipeline.getName(), a.getName()));
}
MultiBranchProject mbp = (MultiBranchProject) item;
BranchSource branchSource = getGitScmSource(mbp);
if (branchSource != null) {
mbp.getSourcesList().replaceBy(Collections.singleton(branchSource));
mbp.scheduleBuild2(0, new CauseAction(new Cause.UserIdCause()));
}
}
return pipeline;
}
use of jenkins.branch.MultiBranchProject in project blueocean-plugin by jenkinsci.
the class GitReadSaveService method getApiUrl.
@Override
public String getApiUrl(@Nonnull Item item) {
if (item instanceof org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) {
MultiBranchProject<?, ?> mbp = (MultiBranchProject<?, ?>) item;
SCMSource s = mbp.getSCMSources().iterator().next();
if (s instanceof GitSCMSource) {
String remote = ((GitSCMSource) s).getRemote();
return remote;
}
}
return null;
}
use of jenkins.branch.MultiBranchProject in project blueocean-plugin by jenkinsci.
the class GitPipelineCreateRequestTest method createPipeline.
@Test
public void createPipeline() throws UnirestException, IOException {
User user = login("vivek", "Vivek Pandey", "vivek.pandey@gmail.com");
Map r = new PipelineBaseTest.RequestBuilder(baseUrl).status(201).jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId())).crumb(crumb).post("/organizations/jenkins/pipelines/").data(MapsHelper.of("name", "pipeline1", "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest", "scmConfig", MapsHelper.of("id", GitScm.ID, "uri", sampleRepo.toString()))).build(Map.class);
assertNotNull(r);
assertEquals("pipeline1", r.get("name"));
MultiBranchProject mbp = (MultiBranchProject) j.getInstance().getItem("pipeline1");
GitSCMSource source = (GitSCMSource) mbp.getSCMSources().get(0);
List<SCMSourceTrait> traits = source.getTraits();
Assert.assertNotNull(SCMTrait.find(traits, BranchDiscoveryTrait.class));
Assert.assertNotNull(SCMTrait.find(traits, CleanAfterCheckoutTrait.class));
Assert.assertNotNull(SCMTrait.find(traits, CleanBeforeCheckoutTrait.class));
Assert.assertNotNull(SCMTrait.find(traits, LocalBranchTrait.class));
}
use of jenkins.branch.MultiBranchProject 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;
Result result = branchIndexing.getResult();
if (result != null) {
jobChannelMessage.set(indexingResult, result.toString());
}
} else if (executable instanceof OrganizationFolder.OrganizationScan) {
OrganizationFolder.OrganizationScan orgScan = (OrganizationFolder.OrganizationScan) executable;
Result result = orgScan.getResult();
if (result != null) {
jobChannelMessage.set(indexingResult, result.toString());
}
}
} else {
jobChannelMessage.set(indexingStatus, "INDEXING");
}
}
} else {
jobChannelMessage.set(indexingStatus, "INDEXING");
}
}
}
}
use of jenkins.branch.MultiBranchProject in project blueocean-plugin by jenkinsci.
the class BitbucketServerScmContentProviderTest method mockMbp.
private MultiBranchProject mockMbp(String credentialId, User user) {
MultiBranchProject mbp = mock(MultiBranchProject.class);
when(mbp.getName()).thenReturn("pipeline1");
when(mbp.getParent()).thenReturn(j.jenkins);
BitbucketSCMSource scmSource = mock(BitbucketSCMSource.class);
when(scmSource.getServerUrl()).thenReturn(apiUrl);
when(scmSource.getCredentialsId()).thenReturn(credentialId);
when(scmSource.getRepoOwner()).thenReturn("TESTP");
when(scmSource.getRepository()).thenReturn("pipeline-demo-test");
when(mbp.getSCMSources()).thenReturn(Collections.singletonList(scmSource));
// mock blueocean credential provider stuff
BlueOceanCredentialsProvider.FolderPropertyImpl folderProperty = mock(BlueOceanCredentialsProvider.FolderPropertyImpl.class);
DescribableList<AbstractFolderProperty<?>, AbstractFolderPropertyDescriptor> properties = new DescribableList<>(mbp);
properties.add(new BlueOceanCredentialsProvider.FolderPropertyImpl(user.getId(), credentialId, BlueOceanCredentialsProvider.createDomain(apiUrl)));
Domain domain = mock(Domain.class);
when(domain.getName()).thenReturn(BitbucketServerScm.DOMAIN_NAME);
when(folderProperty.getDomain()).thenReturn(domain);
when(mbp.getProperties()).thenReturn(properties);
return mbp;
}
Aggregations