本文整理汇总了Java中jenkins.model.Jenkins.getActiveInstance方法的典型用法代码示例。如果您正苦于以下问题:Java Jenkins.getActiveInstance方法的具体用法?Java Jenkins.getActiveInstance怎么用?Java Jenkins.getActiveInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jenkins.model.Jenkins
的用法示例。
在下文中一共展示了Jenkins.getActiveInstance方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: gatherEnvVarsMaster
import jenkins.model.Jenkins; //导入方法依赖的package包/类
@Nonnull
private static Map<String, String> gatherEnvVarsMaster(@Nonnull Job<?, ?> job) throws EnvInjectException {
final Jenkins jenkins;
try {
jenkins = Jenkins.getActiveInstance();
} catch(IllegalStateException ex) {
throw new EnvInjectException(ex);
}
EnvVars env = new EnvVars();
env.put("JENKINS_SERVER_COOKIE", Util.getDigestOf("ServerID:" + jenkins.getSecretKey()));
env.put("HUDSON_SERVER_COOKIE", Util.getDigestOf("ServerID:" + jenkins.getSecretKey())); // Legacy compatibility
env.put("JOB_NAME", job.getFullName());
env.put("JENKINS_HOME", jenkins.getRootDir().getPath());
env.put("HUDSON_HOME", jenkins.getRootDir().getPath()); // legacy compatibility
String rootUrl = jenkins.getRootUrl();
if (rootUrl != null) {
env.put("JENKINS_URL", rootUrl);
env.put("HUDSON_URL", rootUrl); // Legacy compatibility
env.put("JOB_URL", rootUrl + job.getUrl());
}
return env;
}
示例2: doRun
import jenkins.model.Jenkins; //导入方法依赖的package包/类
@Override protected void doRun() throws Exception {
// Trigger reprovisioning as well
Jenkins.getActiveInstance().unlabeledNodeProvisioner.suggestReviewNow();
final List<FleetStateStats> stats = new ArrayList<FleetStateStats>();
for(final Cloud cloud : Jenkins.getActiveInstance().clouds) {
if (!(cloud instanceof EC2FleetCloud))
continue;
// Update the cluster states
final EC2FleetCloud fleetCloud =(EC2FleetCloud) cloud;
LOGGER.log(Level.FINE, "Checking cloud: " + fleetCloud.getLabelString() );
stats.add(fleetCloud.updateStatus());
}
for (final Widget w : Jenkins.getInstance().getWidgets()) {
if (!(w instanceof FleetStatusWidget))
continue;
((FleetStatusWidget)w).setStatusList(stats);
}
}
示例3: find
import jenkins.model.Jenkins; //导入方法依赖的package包/类
/**
* Search in Jenkins for a item with type T based on the job name
* @param jobName job to find, for jobs inside a folder use : {@literal <folder>/<folder>/<jobName>}
* @return the Job matching the given name, or {@code null} when not found
*/
static <T extends Item> T find(String jobName, Class<T> type) {
Jenkins jenkins = Jenkins.getActiveInstance();
// direct search, can be used to find folder based items <folder>/<folder>/<jobName>
T item = jenkins.getItemByFullName(jobName, type);
if (item == null) {
// not found in a direct search, search in all items since the item might be in a folder but given without folder structure
// (to keep it backwards compatible)
for (T allItem : jenkins.getAllItems(type)) {
if (allItem.getName().equals(jobName)) {
item = allItem;
break;
}
}
}
return item;
}
示例4: triggerJobs
import jenkins.model.Jenkins; //导入方法依赖的package包/类
public GogsResults triggerJobs(String jobName, String deliveryID) {
SecurityContext saveCtx = null;
GogsResults result = new GogsResults();
try {
saveCtx = SecurityContextHolder.getContext();
Jenkins instance = Jenkins.getActiveInstance();
if (instance!=null) {
ACL acl = instance.getACL();
acl.impersonate(ACL.SYSTEM);
BuildableItem project = GogsUtils.find(jobName, BuildableItem.class);
if (project != null) {
Cause cause = new GogsCause(deliveryID);
project.scheduleBuild(0, cause);
result.setMessage(String.format("Job '%s' is executed",jobName));
} else {
String msg = String.format("Job '%s' is not defined in Jenkins",jobName);
result.setStatus(404, msg);
LOGGER.warning(msg);
}
}
} catch (Exception e) {
} finally {
SecurityContextHolder.setContext(saveCtx);
}
return result;
}
示例5: getComputer
import jenkins.model.Jenkins; //导入方法依赖的package包/类
/**
* 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.getActiveInstance();
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;
}
示例6: isMultiScmAvailable
import jenkins.model.Jenkins; //导入方法依赖的package包/类
private boolean isMultiScmAvailable() {
final Jenkins jenkins = Jenkins.getActiveInstance();
boolean hasPlugin = jenkins.getPlugin("multiple-scms") != null;
log.debug("Multiple-SCMs plugin found: %s", hasPlugin);
return hasPlugin;
}
示例7: isGitScmAvailable
import jenkins.model.Jenkins; //导入方法依赖的package包/类
private boolean isGitScmAvailable() {
final Jenkins jenkins = Jenkins.getActiveInstance();
boolean hasPlugin = jenkins.getPlugin("git") != null;
log.debug("Git plugin found: %s", hasPlugin);
return hasPlugin;
}