Search in sources :

Example 1 with Resource

use of io.jenkins.blueocean.rest.model.Resource in project blueocean-plugin by jenkinsci.

the class LinkResolverImpl method resolveRun.

private Resource resolveRun(Run run) {
    Resource resource = resolveJob(run.getParent());
    if (resource instanceof BluePipeline) {
        BluePipeline pipeline = (BluePipeline) resource;
        BlueRunContainer blueRunContainer = pipeline.getRuns();
        return blueRunContainer == null ? null : blueRunContainer.get(run.getId());
    }
    return null;
}
Also used : Resource(io.jenkins.blueocean.rest.model.Resource) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) BlueRunContainer(io.jenkins.blueocean.rest.model.BlueRunContainer)

Example 2 with Resource

use of io.jenkins.blueocean.rest.model.Resource in project blueocean-plugin by jenkinsci.

the class BluePipelineFactory method resolve.

/**
 * Given a Job in Jenkins, map that to corresponding blue ocean API object,
 * for example so that you can get its URL.
 */
public static Resource resolve(Item item) {
    BlueOrganization org = OrganizationFactory.getInstance().getContainingOrg(item);
    if (org == null) {
        return null;
    }
    Item nextStep = findNextStep(Jenkins.get(), item);
    for (BluePipelineFactory f : all()) {
        Resource r = f.resolve(nextStep, org.getPipelines(), item, org);
        if (r != null)
            return r;
    }
    return null;
}
Also used : TopLevelItem(hudson.model.TopLevelItem) Item(hudson.model.Item) BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization) Resource(io.jenkins.blueocean.rest.model.Resource)

Example 3 with Resource

use of io.jenkins.blueocean.rest.model.Resource in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method testMultiBranchPipelineQueueContainer.

@Test
public void testMultiBranchPipelineQueueContainer() throws Exception {
    j.jenkins.setQuietPeriod(0);
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    sampleRepo1.init();
    sampleRepo1.write("Jenkinsfile", "stage 'build'\n " + "node {echo 'Building'}\n" + "stage 'test'\nnode { echo 'Testing'}\n" + "sleep 10000 \n" + "stage 'deploy'\nnode { echo 'Deploying'}\n");
    sampleRepo1.write("file", "initial content");
    sampleRepo1.git("add", "Jenkinsfile");
    sampleRepo1.git("commit", "--all", "--message=flow");
    // create feature branch
    sampleRepo1.git("checkout", "-b", "abc");
    sampleRepo1.write("Jenkinsfile", "echo \"branch=${env.BRANCH_NAME}\"; " + "node {" + "   stage ('Build'); " + "   echo ('Building'); " + "   stage ('Test'); sleep 10000; " + "   echo ('Testing'); " + "   stage ('Deploy'); " + "   echo ('Deploying'); " + "}");
    ScriptApproval.get().approveSignature("method java.lang.String toUpperCase");
    sampleRepo1.write("file", "subsequent content1");
    sampleRepo1.git("commit", "--all", "--message=tweaked1");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo1.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    scheduleAndFindBranchProject(mp);
    Resource r = BluePipelineFactory.resolve(mp);
    assertTrue(r instanceof MultiBranchPipelineImpl);
    for (WorkflowJob job : mp.getItems()) {
        Queue.Item item = job.getQueueItem();
        job.setConcurrentBuild(false);
        job.scheduleBuild2(0);
        job.scheduleBuild2(0);
    }
    Queue.Item[] queueItems = Jenkins.get().getQueue().getItems();
    MultiBranchPipelineQueueContainer mbpQueueContainer = new MultiBranchPipelineQueueContainer((MultiBranchPipelineImpl) r);
    Iterator<BlueQueueItem> blueQueueItems = mbpQueueContainer.iterator(0, 100);
    if (queueItems.length > 0) {
        assertTrue(mbpQueueContainer.iterator().hasNext());
        assertEquals("/blue/rest/organizations/jenkins/pipelines/p/queue/", mbpQueueContainer.getLink().getHref());
        BlueQueueItem blueQueueItem = mbpQueueContainer.get(String.valueOf(queueItems[0].getId()));
        assertNotNull(blueQueueItem);
        assertTrue(blueQueueItems.hasNext());
    }
}
Also used : Resource(io.jenkins.blueocean.rest.model.Resource) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) BlueQueueItem(io.jenkins.blueocean.rest.model.BlueQueueItem) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Queue(hudson.model.Queue) BlueQueueItem(io.jenkins.blueocean.rest.model.BlueQueueItem) Test(org.junit.Test)

Example 4 with Resource

use of io.jenkins.blueocean.rest.model.Resource in project blueocean-plugin by jenkinsci.

the class BlueOceanUrlMapperImpl method getUrl.

@Override
public String getUrl(@Nonnull ModelObject modelObject) {
    BlueOrganization organization = getOrganization(modelObject);
    if (organization == null) {
        // no organization, best we can do is to land user on landing page
        return getLandingPagePath();
    }
    String organizationName = organization.getName();
    String baseUrl = getOrgPrefix(organizationName);
    if (modelObject instanceof ModifiableTopLevelItemGroup) {
        return baseUrl;
    } else if (modelObject instanceof Job) {
        BluePipeline blueResource = getJobResource(modelObject);
        if (blueResource != null) {
            return getPipelineUrl(baseUrl, blueResource);
        }
    } else if (modelObject instanceof Run) {
        Run run = (Run) modelObject;
        Job job = run.getParent();
        BluePipeline blueResource = getJobResource(job);
        if (blueResource != null) {
            // encoded and re-encode to do the full monty. Nasty :)
            return baseUrl + "/" + encodeURIComponent(blueResource.getFullName()) + "/detail/" + encodeURIComponent(decodeURIComponent(job.getName())) + "/" + encodeURIComponent(run.getId()) + "/";
        }
    } else if (modelObject instanceof Item) {
        Resource bluePipeline = BluePipelineFactory.resolve((Item) modelObject);
        if (bluePipeline instanceof BlueMultiBranchPipeline) {
            return getPipelineUrl(baseUrl, (BluePipeline) bluePipeline);
        }
    }
    return null;
}
Also used : Item(hudson.model.Item) ModifiableTopLevelItemGroup(jenkins.model.ModifiableTopLevelItemGroup) BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization) Resource(io.jenkins.blueocean.rest.model.Resource) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) Run(hudson.model.Run) Job(hudson.model.Job) BlueMultiBranchPipeline(io.jenkins.blueocean.rest.model.BlueMultiBranchPipeline)

Example 5 with Resource

use of io.jenkins.blueocean.rest.model.Resource in project blueocean-plugin by jenkinsci.

the class PipelineActivityStatePreloader method getFetchData.

@Override
protected FetchData getFetchData(@Nonnull BlueUrlTokenizer blueUrl) {
    BluePipeline pipeline = getPipeline(blueUrl);
    if (pipeline != null) {
        // It's a pipeline page. Let's prefetch the pipeline activity and add them to the page,
        // saving the frontend the overhead of requesting them.
        Container<BlueRun> activitiesContainer = pipeline.getRuns();
        if (activitiesContainer == null) {
            return null;
        }
        Iterator<BlueRun> activitiesIterator = activitiesContainer.iterator(0, DEFAULT_LIMIT);
        JSONArray activities = new JSONArray();
        while (activitiesIterator.hasNext()) {
            Resource blueActivity = activitiesIterator.next();
            try {
                activities.add(JSONObject.fromObject(Export.toJson(blueActivity)));
            } catch (IOException e) {
                LOGGER.log(Level.FINE, String.format("Unable to preload runs for Job '%s'. Activity serialization error.", pipeline.getFullName()), e);
                return null;
            }
        }
        return new FetchData(activitiesContainer.getLink().getHref() + "?start=0&limit=" + DEFAULT_LIMIT, activities.toString());
    }
    // Don't preload any data on the page.
    return null;
}
Also used : BlueRun(io.jenkins.blueocean.rest.model.BlueRun) JSONArray(net.sf.json.JSONArray) Resource(io.jenkins.blueocean.rest.model.Resource) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) IOException(java.io.IOException)

Aggregations

Resource (io.jenkins.blueocean.rest.model.Resource)8 BluePipeline (io.jenkins.blueocean.rest.model.BluePipeline)4 Item (hudson.model.Item)3 Run (hudson.model.Run)3 BlueOrganization (io.jenkins.blueocean.rest.model.BlueOrganization)3 Job (hudson.model.Job)2 BlueRun (io.jenkins.blueocean.rest.model.BlueRun)2 BlueRunContainer (io.jenkins.blueocean.rest.model.BlueRunContainer)2 ItemGroup (hudson.model.ItemGroup)1 Queue (hudson.model.Queue)1 TopLevelItem (hudson.model.TopLevelItem)1 BlueMultiBranchPipeline (io.jenkins.blueocean.rest.model.BlueMultiBranchPipeline)1 BlueQueueItem (io.jenkins.blueocean.rest.model.BlueQueueItem)1 IOException (java.io.IOException)1 BranchSource (jenkins.branch.BranchSource)1 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)1 ModifiableTopLevelItemGroup (jenkins.model.ModifiableTopLevelItemGroup)1 GitSCMSource (jenkins.plugins.git.GitSCMSource)1 SCMSource (jenkins.scm.api.SCMSource)1 JSONArray (net.sf.json.JSONArray)1