Search in sources :

Example 31 with MultiBranchProject

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;
}
Also used : Item(hudson.model.Item) Authentication(org.acegisecurity.Authentication) CauseAction(hudson.model.CauseAction) MultiBranchProject(jenkins.branch.MultiBranchProject) ACL(hudson.security.ACL) BranchSource(jenkins.branch.BranchSource) CheckForNull(javax.annotation.CheckForNull)

Example 32 with MultiBranchProject

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;
}
Also used : MultiBranchProject(jenkins.branch.MultiBranchProject) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource)

Example 33 with MultiBranchProject

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));
}
Also used : User(hudson.model.User) CleanAfterCheckoutTrait(jenkins.plugins.git.traits.CleanAfterCheckoutTrait) SCMSourceTrait(jenkins.scm.api.trait.SCMSourceTrait) CleanBeforeCheckoutTrait(jenkins.plugins.git.traits.CleanBeforeCheckoutTrait) MultiBranchProject(jenkins.branch.MultiBranchProject) GitSCMSource(jenkins.plugins.git.GitSCMSource) Map(java.util.Map) LocalBranchTrait(jenkins.plugins.git.traits.LocalBranchTrait) BranchDiscoveryTrait(jenkins.plugins.git.traits.BranchDiscoveryTrait) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Example 34 with MultiBranchProject

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");
            }
        }
    }
}
Also used : JobChannelMessage(org.jenkinsci.plugins.pubsub.JobChannelMessage) OrganizationFolder(jenkins.branch.OrganizationFolder) BranchIndexing(jenkins.branch.MultiBranchProject.BranchIndexing) Result(hudson.model.Result) Item(hudson.model.Item) QueueTaskMessage(org.jenkinsci.plugins.pubsub.QueueTaskMessage) MultiBranchProject(jenkins.branch.MultiBranchProject) Queue(hudson.model.Queue)

Example 35 with MultiBranchProject

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;
}
Also used : BlueOceanCredentialsProvider(io.jenkins.blueocean.rest.impl.pipeline.credential.BlueOceanCredentialsProvider) DescribableList(hudson.util.DescribableList) MultiBranchProject(jenkins.branch.MultiBranchProject) AbstractFolderPropertyDescriptor(com.cloudbees.hudson.plugins.folder.AbstractFolderPropertyDescriptor) Domain(com.cloudbees.plugins.credentials.domains.Domain) BitbucketSCMSource(com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource) AbstractFolderProperty(com.cloudbees.hudson.plugins.folder.AbstractFolderProperty)

Aggregations

MultiBranchProject (jenkins.branch.MultiBranchProject)52 Test (org.junit.Test)36 StaplerRequest (org.kohsuke.stapler.StaplerRequest)28 GitContent (io.jenkins.blueocean.rest.impl.pipeline.scm.GitContent)18 BufferedReader (java.io.BufferedReader)16 StringReader (java.io.StringReader)16 JSONObject (net.sf.json.JSONObject)16 ServiceException (io.jenkins.blueocean.commons.ServiceException)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 User (hudson.model.User)13 Mailer (hudson.tasks.Mailer)12 BitbucketScmSaveFileRequest (io.jenkins.blueocean.blueocean_bitbucket_pipeline.BitbucketScmSaveFileRequest)6 Job (hudson.model.Job)5 DescribableList (hudson.util.DescribableList)5 ScmFile (io.jenkins.blueocean.rest.impl.pipeline.scm.ScmFile)5 Map (java.util.Map)5 GitSCMSource (jenkins.plugins.git.GitSCMSource)5 GitHubSCMSource (org.jenkinsci.plugins.github_branch_source.GitHubSCMSource)5 BitbucketSCMSource (com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource)4 Item (hudson.model.Item)4