本文整理匯總了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;
}