use of hudson.model.Computer in project vsphere-cloud-plugin by jenkinsci.
the class vSphereCloudSlave method _terminate.
@Override
protected void _terminate(final TaskListener listener) throws IOException, InterruptedException {
try {
Computer computer = toComputer();
if (computer != null) {
final VSphereOfflineCause cause = new VSphereOfflineCause(Messages._vSphereCloudSlave_OfflineReason_ShuttingDown());
computer.disconnect(cause);
vSphereCloud.Log(this, listener, "Disconnected computer %s", vmName);
} else {
vSphereCloud.Log(this, listener, "Can't disconnect computer for %s as there was no Computer node for it.", vmName);
}
} catch (Exception e) {
vSphereCloud.Log(this, listener, e, "Can't disconnect %s", vmName);
}
}
use of hudson.model.Computer in project workflow-job-plugin by jenkinsci.
the class WorkflowJob method poll.
@SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification = "TODO 1.653+ switch to Jenkins.getInstanceOrNull")
@Override
public PollingResult poll(TaskListener listener) {
if (!isBuildable()) {
listener.getLogger().println("Build disabled");
return PollingResult.NO_CHANGES;
}
// TODO 2.11+ call SCMDecisionHandler
// TODO call SCMPollListener
WorkflowRun lastBuild = getLastBuild();
if (lastBuild == null) {
listener.getLogger().println("no previous build to compare to");
// Note that we have no equivalent of AbstractProject.NoSCM because without an initial build we do not know if this project has any SCM at all.
return Queue.getInstance().contains(this) ? PollingResult.NO_CHANGES : PollingResult.BUILD_NOW;
}
WorkflowRun perhapsCompleteBuild = getLastSuccessfulBuild();
if (perhapsCompleteBuild == null) {
perhapsCompleteBuild = lastBuild;
}
if (pollingBaselines == null) {
pollingBaselines = new ConcurrentHashMap<>();
}
PollingResult result = PollingResult.NO_CHANGES;
for (WorkflowRun.SCMCheckout co : perhapsCompleteBuild.checkouts(listener)) {
if (!co.scm.supportsPolling()) {
listener.getLogger().println("polling not supported from " + co.workspace + " on " + co.node);
continue;
}
String key = co.scm.getKey();
SCMRevisionState pollingBaseline = pollingBaselines.get(key);
if (pollingBaseline == null) {
// after a restart, transient cache will be empty
pollingBaseline = co.pollingBaseline;
}
if (pollingBaseline == null) {
listener.getLogger().println("no polling baseline in " + co.workspace + " on " + co.node);
continue;
}
try {
FilePath workspace;
Launcher launcher;
WorkspaceList.Lease lease;
if (co.scm.requiresWorkspaceForPolling()) {
Jenkins j = Jenkins.getInstance();
if (j == null) {
listener.error("Jenkins is shutting down");
continue;
}
Computer c = j.getComputer(co.node);
if (c == null) {
listener.error("no such computer " + co.node);
continue;
}
workspace = new FilePath(c.getChannel(), co.workspace);
launcher = workspace.createLauncher(listener).decorateByEnv(getEnvironment(c.getNode(), listener));
lease = c.getWorkspaceList().acquire(workspace, !isConcurrentBuild());
} else {
workspace = null;
launcher = null;
lease = null;
}
PollingResult r;
try {
r = co.scm.compareRemoteRevisionWith(this, launcher, workspace, listener, pollingBaseline);
if (r.remote != null) {
pollingBaselines.put(key, r.remote);
}
} finally {
if (lease != null) {
lease.release();
}
}
if (r.change.compareTo(result.change) > 0) {
// note that if we are using >1 checkout, we can clobber baseline/remote here; anyway SCMTrigger only calls hasChanges()
result = r;
}
} catch (AbortException x) {
listener.error("polling failed in " + co.workspace + " on " + co.node + ": " + x.getMessage());
} catch (Exception x) {
// TODO 2.43+ use Functions.printStackTrace
listener.error("polling failed in " + co.workspace + " on " + co.node).println(Functions.printThrowable(x).trim());
}
}
return result;
}
use of hudson.model.Computer in project nodejs-plugin by jenkinsci.
the class NodeJSInstallation method getPlatform.
private Platform getPlatform() throws DetectionFailedException {
Platform currentPlatform = platform;
// missed call method forNode
if (currentPlatform == null) {
Computer computer = Computer.currentComputer();
if (computer != null) {
Node node = computer.getNode();
if (node == null) {
throw new DetectionFailedException(Messages.NodeJSBuilders_nodeOffline());
}
currentPlatform = Platform.of(node);
} else {
// pipeline or MasterToSlave use case
currentPlatform = Platform.current();
}
platform = currentPlatform;
}
return currentPlatform;
}
use of hudson.model.Computer in project nodejs-plugin by jenkinsci.
the class NodeJSBuildWrapper method setUp.
/*
* (non-Javadoc)
* @see jenkins.tasks.SimpleBuildWrapper#setUp(jenkins.tasks.SimpleBuildWrapper.Context, hudson.model.Run, hudson.FilePath, hudson.Launcher, hudson.model.TaskListener, hudson.EnvVars)
*/
@Override
public void setUp(final Context context, Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener, EnvVars initialEnvironment) throws IOException, InterruptedException {
// get specific installation for the node
NodeJSInstallation ni = getNodeJS();
if (ni == null) {
throw new IOException(Messages.NodeJSBuilders_noInstallationFound(nodeJSInstallationName));
}
Computer computer = workspace.toComputer();
if (computer == null) {
throw new AbortException(Messages.NodeJSBuilders_nodeOffline());
}
Node node = computer.getNode();
if (node == null) {
throw new AbortException(Messages.NodeJSBuilders_nodeOffline());
}
ni = ni.forNode(node, listener);
ni = ni.forEnvironment(initialEnvironment);
String exec = ni.getExecutable(launcher);
if (exec == null) {
throw new AbortException(Messages.NodeJSBuilders_noExecutableFound(ni.getHome()));
}
ni.buildEnvVars(new EnvVarsAdapter(context));
EnvVars env = initialEnvironment.overrideAll(context.getEnv());
// add npmrc config
if (configId != null) {
ConfigFile cf = new ConfigFile(configId, null, true);
FilePath configFile = ConfigFileManager.provisionConfigFile(cf, env, build, workspace, listener, new ArrayList<String>());
context.env(NodeJSConstants.NPM_USERCONFIG, configFile.getRemote());
build.addAction(new CleanTempFilesAction(configFile.getRemote()));
}
}
use of hudson.model.Computer in project jenkins-client-plugin by openshift.
the class BaseStep method consolidateEnvVars.
// borrowed from openshift pipeline plugin
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;
}
Aggregations