Search in sources :

Example 61 with Jenkins

use of jenkins.model.Jenkins in project blueocean-plugin by jenkinsci.

the class PipelineActivityStatePreloader method getPipeline.

private BluePipeline getPipeline(BlueUrlTokenizer blueUrl) {
    if (addPipelineRuns(blueUrl)) {
        Jenkins jenkins = Jenkins.get();
        String pipelineFullName = blueUrl.getPart(BlueUrlTokenizer.UrlPart.PIPELINE);
        try {
            Item pipelineJob = jenkins.getItemByFullName(pipelineFullName);
            return (BluePipeline) BluePipelineFactory.resolve(pipelineJob);
        } catch (Exception e) {
            LOGGER.log(Level.FINE, String.format("Unable to find Job named '%s'.", pipelineFullName), e);
            return null;
        }
    }
    return null;
}
Also used : Jenkins(jenkins.model.Jenkins) Item(hudson.model.Item) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) IOException(java.io.IOException)

Example 62 with Jenkins

use of jenkins.model.Jenkins in project blueocean-plugin by jenkinsci.

the class PipelineStatePreloader method getFetchData.

@Override
protected FetchData getFetchData(@NonNull BlueUrlTokenizer blueUrl) {
    // e.g. /blue/organizations/jenkins/Pipeline (or a url on that)
    if (!blueUrl.hasPart(BlueUrlTokenizer.UrlPart.PIPELINE)) {
        // Not interested in it
        return null;
    }
    Jenkins jenkins = Jenkins.get();
    String pipelineFullName = blueUrl.getPart(BlueUrlTokenizer.UrlPart.PIPELINE);
    try {
        Item pipelineJobItem = jenkins.getItemByFullName(pipelineFullName);
        if (pipelineJobItem != null) {
            BluePipeline bluePipeline = (BluePipeline) BluePipelineFactory.resolve(pipelineJobItem);
            if (bluePipeline != null) {
                try {
                    return new FetchData(bluePipeline.getLink().getHref(), Export.toJson(bluePipeline));
                } catch (IOException e) {
                    LOGGER.log(Level.FINE, String.format("Unable to preload pipeline '%s'. Serialization error.", pipelineJobItem.getUrl()), e);
                    return null;
                }
            } else {
                LOGGER.log(Level.FINE, String.format("Unable to preload pipeline '%s'. Failed to convert to Blue Ocean Resource.", pipelineJobItem.getUrl()));
                return null;
            }
        }
    } catch (Exception e) {
        LOGGER.log(Level.FINE, String.format("Unable to find pipeline named '%s'.", pipelineFullName), e);
        return null;
    }
    // Don't preload any data on the page.
    return null;
}
Also used : Jenkins(jenkins.model.Jenkins) Item(hudson.model.Item) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) IOException(java.io.IOException) IOException(java.io.IOException)

Example 63 with Jenkins

use of jenkins.model.Jenkins in project blueocean-plugin by jenkinsci.

the class JobAnalytics method calculateAndSend.

public void calculateAndSend() {
    Analytics analytics = Analytics.get();
    if (analytics == null) {
        return;
    }
    Jenkins jenkins = Jenkins.get();
    ExtensionList<JobAnalyticsCheck> checks = ExtensionList.lookup(JobAnalyticsCheck.class);
    ExtensionList<JobAnalyticsExclude> excludes = ExtensionList.lookup(JobAnalyticsExclude.class);
    // Initialize the tally
    Tally tally = new Tally();
    checks.forEach(check -> tally.zero(check.getName()));
    tally.zero(OTHER_CATEGORY);
    jenkins.allItems().forEach(item -> {
        if (excludes.stream().noneMatch(exclude -> exclude.apply(item))) {
            boolean matchFound = false;
            for (JobAnalyticsCheck check : checks) {
                if (check.apply(item)) {
                    tally.count(check.getName());
                    matchFound = true;
                    break;
                }
            }
            if (!matchFound) {
                tally.count(OTHER_CATEGORY);
            }
        }
    });
    analytics.track(new TrackRequest(JOB_STATS_EVENT_NAME, tally.get()));
}
Also used : Jenkins(jenkins.model.Jenkins) TrackRequest(io.jenkins.blueocean.analytics.Analytics.TrackRequest) Analytics(io.jenkins.blueocean.analytics.Analytics)

Example 64 with Jenkins

use of jenkins.model.Jenkins in project support-core-plugin by jenkinsci.

the class FileDescriptorLimit method addContents.

@Override
public void addContents(@NonNull Container container) {
    Jenkins j = Jenkins.get();
    addContents(container, j);
    for (Node node : j.getNodes()) {
        addContents(container, node);
    }
}
Also used : Jenkins(jenkins.model.Jenkins) Node(hudson.model.Node)

Example 65 with Jenkins

use of jenkins.model.Jenkins in project support-core-plugin by jenkinsci.

the class FileDescriptorLimit method addContents.

private void addContents(@NonNull Container container, @NonNull final Node node) {
    Computer c = node.toComputer();
    if (c == null) {
        return;
    }
    if (c instanceof SlaveComputer && !Boolean.TRUE.equals(c.isUnix())) {
        return;
    }
    if (!node.createLauncher(TaskListener.NULL).isUnix()) {
        return;
    }
    String name;
    if (node instanceof Jenkins) {
        name = "master";
    } else {
        name = "slave/" + node.getNodeName();
    }
    container.add(new PrefilteredPrintedContent("nodes/{0}/file-descriptors.txt", name) {

        @Override
        protected void printTo(PrintWriter out, ContentFilter filter) {
            out.println(node.getDisplayName());
            out.println("======");
            out.println();
            try {
                out.println(AsyncResultCache.get(node, fileDescriptorCache, new GetUlimit(filter), "file descriptor info", "N/A: Either no connection to node or no cached result"));
            } catch (IOException e) {
                Functions.printStackTrace(e, out);
            } finally {
                out.flush();
            }
        }
    });
}
Also used : SlaveComputer(hudson.slaves.SlaveComputer) Jenkins(jenkins.model.Jenkins) PrefilteredPrintedContent(com.cloudbees.jenkins.support.api.PrefilteredPrintedContent) Computer(hudson.model.Computer) SlaveComputer(hudson.slaves.SlaveComputer) IOException(java.io.IOException) ContentFilter(com.cloudbees.jenkins.support.filter.ContentFilter) PrintWriter(java.io.PrintWriter)

Aggregations

Jenkins (jenkins.model.Jenkins)73 Test (org.junit.Test)22 ConfiguredWithCode (org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)13 IOException (java.io.IOException)10 File (java.io.File)9 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)9 FlowExecution (org.jenkinsci.plugins.workflow.flow.FlowExecution)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Map (java.util.Map)7 Statement (org.junit.runners.model.Statement)7 CheckForNull (javax.annotation.CheckForNull)6 FilePath (hudson.FilePath)5 Computer (hudson.model.Computer)5 URL (java.net.URL)5 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)5 Issue (org.jvnet.hudson.test.Issue)5 Item (hudson.model.Item)4 Node (hudson.model.Node)4 Date (java.util.Date)4