Java Code Examples for hudson.model.Computer#currentComputer()
The following examples show how to use
hudson.model.Computer#currentComputer() .
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: AnsibleAdHocCommandBuilder.java From ansible-plugin with Apache License 2.0 | 5 votes |
@Override public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath ws, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws InterruptedException, IOException { try { CLIRunner runner = new CLIRunner(run, ws, launcher, listener); Computer computer = Computer.currentComputer(); if (computer == null) { throw new AbortException("The ansible playbook build step requires to be launched on a node"); } String exe = AnsibleInstallation.getExecutable(ansibleName, AnsibleCommand.ANSIBLE, computer.getNode(), listener, run.getEnvironment(listener)); AnsibleAdHocCommandInvocation invocation = new AnsibleAdHocCommandInvocation(exe, run, ws, listener); invocation.setHostPattern(hostPattern); invocation.setInventory(inventory); invocation.setModule(module); invocation.setModuleCommand(command); invocation.setSudo(sudo, sudoUser); invocation.setForks(forks); invocation.setCredentials(StringUtils.isNotBlank(credentialsId) ? CredentialsProvider.findCredentialById(credentialsId, StandardUsernameCredentials.class, run) : null); invocation.setAdditionalParameters(additionalParameters); invocation.setHostKeyCheck(hostKeyChecking); invocation.setUnbufferedOutput(unbufferedOutput); invocation.setColorizedOutput(colorizedOutput); if (!invocation.execute(runner)) { throw new AbortException("Ansible Ad-Hoc command execution failed"); } } catch (IOException ioe) { Util.displayIOException(ioe, listener); ioe.printStackTrace(listener.fatalError(hudson.tasks.Messages.CommandInterpreter_CommandFailed())); throw ioe; } catch (AnsibleInvocationException aie) { listener.fatalError(aie.getMessage()); throw new AbortException(aie.getMessage()); } }
Example 2
Source File: AnsiblePlaybookBuilder.java From ansible-plugin with Apache License 2.0 | 5 votes |
@Override public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath ws, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws InterruptedException, IOException { Computer computer = Computer.currentComputer(); if (computer == null) { throw new AbortException("The ansible playbook build step requires to be launched on a node"); } perform(run, computer.getNode(), ws, launcher, listener, run.getEnvironment(listener)); }
Example 3
Source File: ZAProxy.java From zaproxy-plugin with MIT License | 5 votes |
/** * Set the JDK to use to start ZAP. * * @param build * @param listener the listener to display log during the job execution in jenkins * @param env list of environment variables. Used to set the path to the JDK * @throws IOException * @throws InterruptedException */ private void computeJdkToUse(AbstractBuild<?, ?> build, BuildListener listener, EnvVars env) throws IOException, InterruptedException { JDK jdkToUse = getJdkToUse(build.getProject()); if (jdkToUse != null) { Computer computer = Computer.currentComputer(); // just in case we are not in a build if (computer != null) { jdkToUse = jdkToUse.forNode(computer.getNode(), listener); } jdkToUse.buildEnvVars(env); } }
Example 4
Source File: DockerRunListener.java From docker-plugin with MIT License | 5 votes |
@Override public void onStarted(Run<?, ?> run, TaskListener listener) { final Computer computer = Computer.currentComputer(); if (computer instanceof DockerComputer) { final DockerComputer dockerComputer = (DockerComputer) computer; final DockerTransientNode node = dockerComputer.getNode(); if (node != null) { run.addAction(new DockerBuildAction(node)); } } }
Example 5
Source File: BaseStep.java From jenkins-client-plugin with Apache License 2.0 | 4 votes |
protected Map<String, String> consolidateEnvVars(TaskListener listener, AbstractBuild<?, ?> build, Launcher launcher) { // EnvVars extends TreeMap TreeMap<String, String> overrides = new TreeMap<String, String>(); // merge from all potential sources if (build != null) { try { EnvVars buildEnv = build.getEnvironment(listener); if (isVerbose()) listener.getLogger() .println("build env vars: " + buildEnv); overrides.putAll(buildEnv); } catch (IOException | InterruptedException e) { if (isVerbose()) e.printStackTrace(listener.getLogger()); } } try { EnvVars computerEnv = null; Computer computer = Computer.currentComputer(); if (computer != null) { computerEnv = computer.getEnvironment(); } else { if (launcher != null) computer = launcher.getComputer(); if (computer != null) { computerEnv = computer.getEnvironment(); } } if (isVerbose()) listener.getLogger().println( "computer env vars: " + computerEnv); if (computerEnv != null) overrides.putAll(computerEnv); } catch (IOException | InterruptedException e2) { if (isVerbose()) e2.printStackTrace(listener.getLogger()); } return overrides; }
Example 6
Source File: BaseStep.java From jenkins-client-plugin with Apache License 2.0 | 4 votes |
protected Map<String, String> consolidateEnvVars(TaskListener listener, AbstractBuild<?, ?> build, Launcher launcher) { // EnvVars extends TreeMap TreeMap<String, String> overrides = new TreeMap<String, String>(); // merge from all potential sources if (build != null) { try { EnvVars buildEnv = build.getEnvironment(listener); if (isVerbose()) listener.getLogger() .println("build env vars: " + buildEnv); overrides.putAll(buildEnv); } catch (IOException | InterruptedException e) { if (isVerbose()) e.printStackTrace(listener.getLogger()); } } try { EnvVars computerEnv = null; Computer computer = Computer.currentComputer(); if (computer != null) { computerEnv = computer.getEnvironment(); } else { if (launcher != null) computer = launcher.getComputer(); if (computer != null) { computerEnv = computer.getEnvironment(); } } if (isVerbose()) listener.getLogger().println( "computer env vars: " + computerEnv); if (computerEnv != null) overrides.putAll(computerEnv); } catch (IOException | InterruptedException e2) { if (isVerbose()) e2.printStackTrace(listener.getLogger()); } return overrides; }