jenkins.model.Jenkins.getNode()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(303)

本文整理了Java中jenkins.model.Jenkins.getNode()方法的一些代码示例,展示了Jenkins.getNode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jenkins.getNode()方法的具体详情如下:
包路径:jenkins.model.Jenkins
类名称:Jenkins
方法名:getNode

Jenkins.getNode介绍

[英]Gets the agent node of the give name, hooked under this Jenkins.
[中]获取给定名称的代理节点,挂接在此Jenkins下。

代码示例

代码示例来源:origin: jenkinsci/jenkins

/**
 * Returns the {@link Node} that this computer represents.
 *
 * @return
 *      null if the configuration has changed and the node is removed, yet the corresponding {@link Computer}
 *      is not yet gone.
 */
@CheckForNull
public Node getNode() {
  Jenkins j = Jenkins.getInstanceOrNull(); // TODO confirm safe to assume non-null and use getInstance()
  if (j == null) {
    return null;
  }
  if (nodeName == null) {
    return j;
  }
  return j.getNode(nodeName);
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Accepts the update to the node configuration.
 */
@RequirePOST
public void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException, FormException {
  checkPermission(CONFIGURE);
  String proposedName = Util.fixEmptyAndTrim(req.getSubmittedForm().getString("name"));
  Jenkins.checkGoodName(proposedName);
  Node node = getNode();
  if (node == null) {
    throw new ServletException("No such node " + nodeName);
  }
  if ((!proposedName.equals(nodeName))
      && Jenkins.getActiveInstance().getNode(proposedName) != null) {
    throw new FormException(Messages.ComputerSet_SlaveAlreadyExists(proposedName), "name");
  }
  String nExecutors = req.getSubmittedForm().getString("numExecutors");
  if (StringUtils.isBlank(nExecutors) || Integer.parseInt(nExecutors)<=0) {
    throw new FormException(Messages.Slave_InvalidConfig_Executors(nodeName), "numExecutors");
  }
  Node result = node.reconfigure(req, req.getSubmittedForm());
  Jenkins.getInstance().getNodesObject().replaceNode(this.getNode(), result);
  // take the user back to the agent top page.
  rsp.sendRedirect2("../" + result.getNodeName() + '/');
}

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

@Test
@ConfiguredWithCode("BackwardCompatibilityTest.yml")
public void shloud_accept_legacy_symbols_on_descriptors() throws Exception {
  final List<Node> nodes = j.jenkins.getNodes();
  System.out.println(nodes);
  assertNotNull(j.jenkins.getNode("foo"));
  assertNotNull(j.jenkins.getNode("bar"));
  assertNotNull(j.jenkins.getNode("qix"));
  // see # see https://github.com/jenkinsci/jenkins/pull/3475
  // assertNotNull(j.jenkins.getNode("zot"));
  final List<ObsoleteConfigurationMonitor.Error> errors = ObsoleteConfigurationMonitor.get().getErrors();
  assertEquals("'DumbSlave' is obsolete, please use 'dumb'", errors.get(0).message);
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Returns a {@link Slave} on which this build was done.
 *
 * @return
 *      null, for example if the agent that this build run no longer exists.
 */
public @CheckForNull Node getBuiltOn() {
  if (builtOn==null || builtOn.equals(""))
    return Jenkins.getInstance();
  else
    return Jenkins.getInstance().getNode(builtOn);
}

代码示例来源:origin: jenkinsci/jenkins

@Override
public int parseArguments(Parameters params) throws CmdLineException {
  String nodeName = params.getParameter(0);
  final Node node = Jenkins.get().getNode(nodeName);
  if (node == null) throw new IllegalArgumentException("No such node '" + nodeName + "'");
  setter.addValue(node);
  return 1;
}

代码示例来源:origin: jenkinsci/jenkins

node = jenkins.getNode(node_s);

代码示例来源:origin: jenkinsci/jenkins

/**
 * Makes sure that the given name is good as an agent name.
 * @return trimmed name if valid; throws ParseException if not
 */
public String checkName(String name) throws Failure {
  if(name==null)
    throw new Failure("Query parameter 'name' is required");
  name = name.trim();
  Jenkins.checkGoodName(name);
  if(Jenkins.getInstance().getNode(name)!=null)
    throw new Failure(Messages.ComputerSet_SlaveAlreadyExists(name));
  // looks good
  return name;
}

代码示例来源:origin: jenkinsci/jenkins

Slave node = (Slave) Jenkins.getInstance().getNode(name);

代码示例来源:origin: jenkinsci/jenkins

@Override
protected int run() throws Exception {
  final Jenkins jenkins = Jenkins.getActiveInstance();
  jenkins.checkPermission(Computer.CREATE);
  final Node newNode = (Node) Jenkins.XSTREAM2.fromXML(stdin);
  if (nodeName != null) {
    // Using deprecated method but it's contract is preserved
    newNode.setNodeName(nodeName);
  }
  if(newNode instanceof Slave) { //change userId too
    User user = User.current();
    ((Slave) newNode).setUserId(user==null ? "anonymous" : user.getId());
  }
  if (jenkins.getNode(newNode.getNodeName()) != null) {
    throw new IllegalStateException("Node '" + newNode.getNodeName() + "' already exists");
  }
  jenkins.addNode(newNode);
  return 0;
}

代码示例来源:origin: jenkinsci/jenkins

name = checkName(name);
Node src = app.getNode(from);
if(src==null) {
  if (Util.fixEmpty(from) == null) {

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

@Test
@ConfiguredWithCode(value = {"merge1.yml", "merge3.yml"}, expected = ConfiguratorException.class)
public void shouldMergeYamlConfig() {
  assertEquals("Configured by configuration-as-code-plugin", j.jenkins.getSystemMessage());
  assertEquals(0, j.jenkins.getNumExecutors());
  assertNotNull(j.jenkins.getNode("agent1"));
  assertNotNull(j.jenkins.getNode("agent3"));
}

代码示例来源:origin: org.jenkins-ci.plugins.workflow/workflow-durable-task-step

@SuppressFBWarnings(value="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification="TODO 1.653+ switch to Jenkins.getInstanceOrNull")
@Override public Node getLastBuiltOn() {
  if (label == null) {
    return null;
  }
  Jenkins j = Jenkins.getInstance();
  if (j == null) {
    return null;
  }
  return j.getNode(label);
}

代码示例来源:origin: jenkinsci/docker-slaves-plugin

@Override public Node getLastBuiltOn() {
  if (label == null) {
    return null;
  }
  Jenkins j = Jenkins.getInstance();
  if (j == null) {
    return null;
  }
  return j.getNode(label);
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

/**
 * Returns a {@link Slave} on which this build was done.
 *
 * @return
 *      null, for example if the agent that this build run no longer exists.
 */
public @CheckForNull Node getBuiltOn() {
  if (builtOn==null || builtOn.equals(""))
    return Jenkins.getInstance();
  else
    return Jenkins.getInstance().getNode(builtOn);
}

代码示例来源:origin: jenkinsci/envinject-plugin

private boolean isActiveSlave(@CheckForNull Computer c) {
  if (c == null) {
    return false;
  }
  Node slave = Jenkins.getActiveInstance().getNode(c.getName());
  return slave != null;
}

代码示例来源:origin: jenkinsci/docker-plugin

/**
 * If the build was workflow, get the ID of that channel.
 */
public static Optional<DockerCloud> getCloudForChannel(VirtualChannel channel) {
  if( channel instanceof Channel) {
    Channel c = (Channel)channel;
    Node node = Jenkins.getInstance().getNode( c.getName() );
    if (node instanceof DockerTransientNode) {
      return Optional.of(((DockerTransientNode) node).getCloud());
    }
  }
  return Optional.empty();
}

代码示例来源:origin: org.jenkins-ci.plugins/credentials

/**
 * Returns the {@link Node}.
 *
 * @return the {@link Node} or {@code null} if either the node no longer exists or the current authentication
 * does not have permission to access the node.
 */
@CheckForNull
public Node getNode() {
  return nodeName.isEmpty() ? Jenkins.getActiveInstance() : Jenkins.getActiveInstance().getNode(nodeName);
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

@Override
public int parseArguments(Parameters params) throws CmdLineException {
  String nodeName = params.getParameter(0);
  final Node node = Jenkins.getInstance().getNode(nodeName);
  if (node == null) throw new IllegalArgumentException("No such node '" + nodeName + "'");
  setter.addValue(node);
  return 1;
}

代码示例来源:origin: jenkinsci/docker-plugin

@Override
  protected void finished(StepContext context) throws Exception {
    final DockerTransientNode node = (DockerTransientNode) Jenkins.getInstance().getNode(nodeName);
    if (node != null) {
      TaskListener listener = context.get(TaskListener.class);
      listener.getLogger().println("Terminating docker node ...");
      node.terminate(listener);
      Jenkins.getInstance().removeNode(node);
    }
  }
}

代码示例来源:origin: jenkinsci/jenkins-test-harness

@SuppressWarnings("unchecked")
protected <N extends Node> N configRoundtrip(N node) throws Exception {
  submit(createWebClient().goTo("/computer/" + node.getNodeName() + "/configure").getFormByName("config"));
  return (N) jenkins.getNode(node.getNodeName());
}

相关文章

Jenkins类方法