Java Code Examples for jenkins.model.Jenkins#getComputers()

The following examples show how to use jenkins.model.Jenkins#getComputers() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DbBackedBuild.java    From DotCi with MIT License 6 votes vote down vote up
@Override
@Exported
public Executor getExecutor() {
    final Jenkins jenkins = Jenkins.getInstance();
    if (jenkins == null) {
        return null;
    }
    for (final Computer computer : jenkins.getComputers()) {
        for (final Executor executor : computer.getExecutors()) {
            if (isCurrent(executor)) {
                return executor;
            }
        }
    }
    return null;
}
 
Example 2
Source File: FolderAuthorizationStrategyManagementLink.java    From folder-auth-plugin with MIT License 5 votes vote down vote up
/**
 * Get all {@link Computer}s in the system
 *
 * @return all Computers in the system
 */
@Nonnull
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // used by index.jelly
public List<Computer> getAllComputers() {
    Jenkins jenkins = Jenkins.get();
    jenkins.checkPermission(Jenkins.ADMINISTER);
    Computer[] computers;

    try (ACLContext ignored = ACL.as(ACL.SYSTEM)) {
        computers = jenkins.getComputers();
    }

    return Arrays.asList(computers);
}
 
Example 3
Source File: Computers.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Exported(inline=true)
public ComputerInfo[] getComputers() throws Exception {
    List<ComputerInfo> info = new ArrayList<>();
    Jenkins j = Jenkins.getInstance();
    for (Computer c : j.getComputers()) {
        info.add(new ComputerInfo(getLink(), c));
    }
    return info.toArray(new ComputerInfo[info.size()]);
}
 
Example 4
Source File: WithMavenStepExecution2.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
/**
 * Gets the computer for the current launcher.
 *
 * @return the computer
 * @throws AbortException in case of error.
 */
@Nonnull
private Computer getComputer() throws AbortException {
    if (computer != null) {
        return computer;
    }

    String node = null;
    Jenkins j = Jenkins.getInstance();

    for (Computer c : j.getComputers()) {
        if (c.getChannel() == launcher.getChannel()) {
            node = c.getName();
            break;
        }
    }

    if (node == null) {
        throw new AbortException("Could not find computer for the job");
    }

    computer = j.getComputer(node);
    if (computer == null) {
        throw new AbortException("No such computer " + node);
    }

    if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.log(Level.FINE, "Computer: {0}", computer.getName());
        try {
            LOGGER.log(Level.FINE, "Env: {0}", computer.getEnvironment());
        } catch (IOException | InterruptedException e) {// ignored
        }
    }
    return computer;
}
 
Example 5
Source File: JenkinsRuleHelpers.java    From yet-another-docker-plugin with MIT License 5 votes vote down vote up
/**
 * Returns true if Hudson is building something or going to build something.
 */
public static boolean isSomethingHappening(Jenkins jenkins) {
    if (!jenkins.getQueue().isEmpty())
        return true;
    for (Computer n : jenkins.getComputers())
        if (!n.isIdle())
            return true;
    return false;
}