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

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

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

Jenkins.getActiveInstance介绍

暂无

代码示例

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

@Deprecated
public GroovyHookScript(String hook) {
  this(hook, Jenkins.getActiveInstance());
}

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

@Override
  protected int run() throws Exception {
    Jenkins.getActiveInstance().doCancelQuietDown();
    return 0;
  }
}

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

@Override
  protected int run() throws Exception {
    Jenkins.getActiveInstance().doQuietDown(block, timeout);
    return 0;
  }
}

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

@Override
protected Iterable<Node> getNodes() {
  return Jenkins.getActiveInstance().getNodes();
}

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

private static File getTargetFile(String name) {
    return new File(Jenkins.getActiveInstance().getPluginManager().rootDir,name+".jpi");
  }
}

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

protected UnlabeledNodesIterator() {
  super(Jenkins.getActiveInstance().getNodes().iterator());
}

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

/**
 * Computes the key that identifies this Hudson among other Hudsons that the user has a credential for.
 */
@VisibleForTesting
String getPropertyKey() {
  Jenkins j = Jenkins.getActiveInstance();
  String url = j.getRootUrl();
  if (url!=null)  return url;
  
  return j.getLegacyInstanceId();
}

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

/**
 * Get the stored version of Jenkins, as stored by
 * {@link #doConfigSubmit(org.kohsuke.stapler.StaplerRequest, org.kohsuke.stapler.StaplerResponse)}.
 * <p>
 * Parses the version into {@link VersionNumber}, or null if it's not parseable as a version number
 * (such as when Jenkins is run with "mvn hudson-dev:run")
 * @since 2.0
 */
@Restricted(NoExternalUse.class)
public @CheckForNull static VersionNumber getStoredVersion() {
  return toVersion(Jenkins.getActiveInstance().version);
}

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

/**
 * URLs to download from.
 */
public List<String> getUrls() {
  List<String> updateSites = new ArrayList<String>();
  for (UpdateSite site : Jenkins.getActiveInstance().getUpdateCenter().getSiteList()) {
    String siteUrl = site.getUrl();
    int baseUrlEnd = siteUrl.indexOf("update-center.json");
    if (baseUrlEnd != -1) {
      String siteBaseUrl = siteUrl.substring(0, baseUrlEnd);
      updateSites.add(siteBaseUrl + "updates/" + url);
    } else {
      LOGGER.log(Level.WARNING, "Url {0} does not look like an update center:", siteUrl);
    }
  }
  return updateSites;
}

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

@Override
protected int run() throws Exception {
  Jenkins.getActiveInstance().getQueue().clear();
  return 0;
}

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

@Override
protected int run() {
  // this allows the caller to manipulate the JVM state, so require the admin privilege.
  Jenkins.getActiveInstance().checkPermission(Jenkins.RUN_SCRIPTS);
  // this being remote means no jline capability is available
  System.setProperty("jline.terminal", UnsupportedTerminal.class.getName());
  TerminalFactory.reset();
  StringBuilder commandLine = new StringBuilder();
  for (String arg : args) {
    if (commandLine.length() > 0) {
      commandLine.append(" ");
    }
    commandLine.append(arg);
  }
  Groovysh shell = createShell(stdin, stdout, stderr);
  return shell.run(commandLine.toString());
}

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

/**
 * Gets all the job properties configured for this job.
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public Map<JobPropertyDescriptor, JobProperty<? super JobT>> getProperties() {
  Map result = Descriptor.toMap((Iterable) properties);
  if (logRotator != null) {
    result.put(Jenkins.getActiveInstance().getDescriptorByType(BuildDiscarderProperty.DescriptorImpl.class), new BuildDiscarderProperty(logRotator));
  }
  return result;
}

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

@Override
public Object onConvert(Type targetType, Class targetTypeErasure, Object jsonSource) {
  if (jsonSource instanceof JSONObject) {
    JSONObject json = (JSONObject) jsonSource;
    if (isApplicable(targetTypeErasure, json)) {
      LOGGER.log(Level.FINE, "switching to newInstance {0} {1}", new Object[] {targetTypeErasure.getName(), json});
      try {
        return Jenkins.getActiveInstance().getDescriptor(targetTypeErasure).newInstance(Stapler.getCurrentRequest(), json);
      } catch (Exception x) {
        LOGGER.log(Level.WARNING, "falling back to default instantiation " + targetTypeErasure.getName() + " " + json, x);
      }
    }
  } else {
    LOGGER.log(Level.FINER, "ignoring non-object {0}", jsonSource);
  }
  return oldInterceptor.onConvert(targetType, targetTypeErasure, jsonSource);
}

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

public void doCommand(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
  final Jenkins jenkins = Jenkins.getActiveInstance();
  jenkins.checkPermission(Jenkins.READ);
  // Strip trailing slash
  final String commandName = req.getRestOfPath().substring(1);
  CLICommand command = CLICommand.clone(commandName);
  if (command == null) {
    rsp.sendError(HttpServletResponse.SC_NOT_FOUND, "No such command");
    return;
  }
  req.setAttribute("command", command);
  req.getView(this, "command.jelly").forward(req, rsp);
}

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

@RequirePOST
public HttpResponse doDoUninstall() throws IOException {
  Jenkins jenkins = Jenkins.getActiveInstance();
  
  jenkins.checkPermission(Jenkins.ADMINISTER);
  archive.delete();
  // Redo who depends on who.
  jenkins.getPluginManager().resolveDependantPlugins();
  return HttpResponses.redirectViaContextPath("/pluginManager/installed");   // send back to plugin manager
}

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

/**
 * Auto-discovers {@link OptionHandler}s and add them to the given command line parser.
 */
protected void registerOptionHandlers() {
  try {
    for (Class c : Index.list(OptionHandlerExtension.class, Jenkins.getActiveInstance().pluginManager.uberClassLoader,Class.class)) {
      Type t = Types.getBaseClass(c, OptionHandler.class);
      CmdLineParser.registerHandler(Types.erasure(Types.getTypeArgument(t,0)), c);
    }
  } catch (IOException e) {
    throw new Error(e);
  }
}

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

protected void runCli(Connection c) throws IOException, InterruptedException {
      ChannelBuilder cb;
      String name = "CLI channel from " + socket.getInetAddress();

      // Connection can contain cipher wrapper, which can't be NIO-ed.
//            if (hub!=null)
//                cb = hub.newChannelBuilder(name, Computer.threadPoolForRemoting);
//            else
        cb = new ChannelBuilder(name, Computer.threadPoolForRemoting);

      Channel channel = cb
          .withMode(Mode.BINARY)
          .withRestricted(true)
          .withBaseLoader(Jenkins.getActiveInstance().pluginManager.uberClassLoader)
          .build(new BufferedInputStream(c.in), new BufferedOutputStream(c.out));

      channel.setProperty(CliEntryPoint.class.getName(),new CliManagerImpl(channel));
      channel.join();
    }
  }

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

@Override
  protected int run() throws Exception {

    final Jenkins jenkins = Jenkins.getActiveInstance();
    jenkins.checkPermission(View.CREATE);

    View newView;
    try {

      newView = View.createViewFromXML(viewName, stdin);
    } catch (Failure ex) {
      throw new IllegalArgumentException("Invalid view name: " + ex.getMessage());
    }

    final String newName = newView.getViewName();
    if (jenkins.getView(newName) != null) {
      throw new IllegalStateException("View '" + newName + "' already exists");
    }

    jenkins.addView(newView);

    return 0;
  }
}

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

@Override
protected int run() throws Exception {
  if (!Jenkins.getActiveInstance().hasPermission(Jenkins.READ)) {
    throw new AccessDeniedException("You must authenticate to access this Jenkins.\n"
        + CLI.usage());
  }
  if (command != null)
    return showCommandDetails();
  showAllCommands();
  return 0;
}

代码示例来源: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;
}

相关文章

Jenkins类方法