本文整理了Java中jenkins.model.Jenkins.getRootUrl()
方法的一些代码示例,展示了Jenkins.getRootUrl()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jenkins.getRootUrl()
方法的具体详情如下:
包路径:jenkins.model.Jenkins
类名称:Jenkins
方法名:getRootUrl
[英]Gets the absolute URL of Jenkins, such as http://localhost/jenkins/.
This method first tries to use the manually configured value, then fall back to #getRootUrlFromRequest. It is done in this order so that it can work correctly even in the face of a reverse proxy.
[中]获取Jenkins的绝对URL,例如http://localhost/jenkins/.
此方法首先尝试使用手动配置的值,然后返回到#getRootUrlFromRequest。它是按此顺序进行的,以便即使在面对反向代理时也能正常工作。
代码示例来源:origin: jenkinsci/jenkins
/**
* Is Jenkins running in HTTPS?
*
* Note that we can't really trust {@link StaplerRequest#isSecure()} because HTTPS might be terminated
* in the reverse proxy.
*/
public boolean isRootUrlSecure() {
String url = getRootUrl();
return url!=null && url.startsWith("https");
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public String getUrlName() {
String urlName = Jenkins.getInstance().getRootUrl() + URL_NAME;
return urlName;
}
代码示例来源: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
/**
* The URL of the user page.
*/
@Exported(visibility = 999)
public @Nonnull
String getAbsoluteUrl() {
return Jenkins.get().getRootUrl() + getUrl();
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Infers the hudson installation URL from the given request.
*/
public static String inferHudsonURL(StaplerRequest req) {
String rootUrl = Jenkins.getInstance().getRootUrl();
if(rootUrl !=null)
// prefer the one explicitly configured, to work with load-balancer, frontend, etc.
return rootUrl;
StringBuilder buf = new StringBuilder();
buf.append(req.getScheme()).append("://");
buf.append(req.getServerName());
if(! (req.getScheme().equals("http") && req.getLocalPort()==80 || req.getScheme().equals("https") && req.getLocalPort()==443))
buf.append(':').append(req.getLocalPort());
buf.append(req.getContextPath()).append('/');
return buf.toString();
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Obtains the host name of the Hudson server that clients can use to talk back to.
* <p>
* This is primarily used in {@code slave-agent.jnlp.jelly} to specify the destination
* that the agents talk to.
*/
public String getServerName() {
// Try to infer this from the configured root URL.
// This makes it work correctly when Hudson runs behind a reverse proxy.
String url = Jenkins.getInstance().getRootUrl();
try {
if(url!=null) {
String host = new URL(url).getHost();
if(host!=null)
return host;
}
} catch (MalformedURLException e) {
// fall back to HTTP request
}
return Stapler.getCurrentRequest().getServerName();
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Returns the absolute URL of this item. This relies on the current
* {@link StaplerRequest} to figure out what the host name is,
* so can be used only during processing client requests.
*
* @return
* absolute URL.
* @throws IllegalStateException
* if the method is invoked outside the HTTP request processing.
*
* @deprecated
* This method shall <b>NEVER</b> be used during HTML page rendering, as it won't work with
* network set up like Apache reverse proxy.
* This method is only intended for the remote API clients who cannot resolve relative references
* (even this won't work for the same reason, which should be fixed.)
*/
@Deprecated
default String getAbsoluteUrl() {
String r = Jenkins.getInstance().getRootUrl();
if(r==null)
throw new IllegalStateException("Root URL isn't configured yet. Cannot compute absolute URL.");
return Util.encode(r+getUrl());
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Resolve an avatar image URL string for the user.
* Note that this method must be called from an HTTP request to be reliable; else use {@link #resolveOrNull}.
* @param u user
* @param avatarSize the preferred image size, "[width]x[height]"
* @return a URL string for a user Avatar image.
*/
public static String resolve(User u, String avatarSize) {
String avatar = resolveOrNull(u, avatarSize);
return avatar != null ? avatar : Jenkins.getInstance().getRootUrl() + Functions.getResourcePath() + "/images/" + avatarSize + "/user.png";
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Gets the absolute URL of this view.
*/
@Exported(visibility=2,name="url")
public String getAbsoluteUrl() {
return Jenkins.getInstance().getRootUrl()+getUrl();
}
代码示例来源:origin: jenkinsci/gitlab-plugin
private StringBuilder retrieveProjectUrl(Job<?, ?> project) {
return new StringBuilder()
.append(Jenkins.getInstance().getRootUrl())
.append(GitLabWebHook.WEBHOOK_URL)
.append(retrieveParentUrl(project))
.append('/').append(Util.rawEncode(project.getName()));
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public ConsoleAnnotator annotate(Object context, MarkupText text, int charPos) {
String url = this.url;
if (url.startsWith("/")) {
StaplerRequest req = Stapler.getCurrentRequest();
if (req!=null) {
// if we are serving HTTP request, we want to use app relative URL
url = req.getContextPath()+url;
} else {
// otherwise presumably this is rendered for e-mails and other non-HTTP stuff
url = Jenkins.getInstance().getRootUrl()+url.substring(1);
}
}
text.addMarkup(charPos, charPos + length, "<a href='" + url + "'"+extraAttributes()+">", "</a>");
return null;
}
代码示例来源:origin: jenkinsci/jenkins
public HttpResponse doTest() {
String referer = Stapler.getCurrentRequest().getReferer();
Jenkins j = Jenkins.getInstance();
// May need to send an absolute URL, since handling of HttpRedirect with a relative URL does not currently honor X-Forwarded-Proto/Port at all.
String redirect = j.getRootUrl() + "administrativeMonitor/" + id + "/testForReverseProxySetup/" + (referer != null ? Util.rawEncode(referer) : "NO-REFERER") + "/";
LOGGER.log(Level.FINE, "coming from {0} and redirecting to {1}", new Object[] {referer, redirect});
return new HttpRedirect(redirect);
}
代码示例来源:origin: jenkinsci/jenkins
String rootURL = jenkins.getRootUrl();
if (rootURL==null) return null;
代码示例来源:origin: jenkinsci/jenkins
tag(rsp,"url", jenkins.getRootUrl());
tag(rsp,"server-id", jenkins.getLegacyInstanceId());
tag(rsp,"slave-port",tal==null?null:tal.getPort());
代码示例来源:origin: jenkinsci/jenkins
/**
* Sends the RSS feed to the client.
*
* @param title
* Title of the feed.
* @param url
* URL of the model object that owns this feed. Relative to the context root.
* @param entries
* Entries to be listed in the RSS feed.
* @param adapter
* Controls how to render entries to RSS.
*/
public static <E> void forwardToRss(String title, String url, Collection<? extends E> entries, FeedAdapter<E> adapter, StaplerRequest req, HttpServletResponse rsp) throws IOException, ServletException {
req.setAttribute("adapter",adapter);
req.setAttribute("title",title);
req.setAttribute("url",url);
req.setAttribute("entries",entries);
req.setAttribute("rootURL", Jenkins.getInstance().getRootUrl());
String flavor = req.getParameter("flavor");
if(flavor==null) flavor="atom";
flavor = flavor.replace('/', '_'); // Don't allow path to any jelly
req.getView(Jenkins.getInstance(),"/hudson/"+flavor+".jelly").forward(req,rsp);
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Creates an environment variable override to be used for launching processes on this node.
*
* @see ProcStarter#envs(Map)
* @since 1.489
*/
public @Nonnull EnvVars buildEnvironment(@Nonnull TaskListener listener) throws IOException, InterruptedException {
EnvVars env = new EnvVars();
Node node = getNode();
if (node==null) return env; // bail out
for (NodeProperty nodeProperty: Jenkins.getInstance().getGlobalNodeProperties()) {
nodeProperty.buildEnvVars(env,listener);
}
for (NodeProperty nodeProperty: node.getNodeProperties()) {
nodeProperty.buildEnvVars(env,listener);
}
// TODO: hmm, they don't really belong
String rootUrl = Jenkins.getInstance().getRootUrl();
if(rootUrl!=null) {
env.put("HUDSON_URL", rootUrl); // Legacy.
env.put("JENKINS_URL", rootUrl);
}
return env;
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public void buildEnvironmentFor(Run r, EnvVars env, TaskListener listener) throws IOException, InterruptedException {
Computer c = Computer.currentComputer();
if (c!=null){
EnvVars compEnv = c.getEnvironment().overrideAll(env);
env.putAll(compEnv);
}
env.put("BUILD_DISPLAY_NAME",r.getDisplayName());
Jenkins j = Jenkins.getInstance();
String rootUrl = j.getRootUrl();
if(rootUrl!=null) {
env.put("BUILD_URL", rootUrl+r.getUrl());
}
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public void buildEnvironmentFor(Job j, EnvVars env, TaskListener listener) throws IOException, InterruptedException {
Jenkins jenkins = Jenkins.getInstance();
String rootUrl = jenkins.getRootUrl();
if(rootUrl!=null) {
env.put("JENKINS_URL", rootUrl);
env.put("HUDSON_URL", rootUrl); // Legacy compatibility
env.put("JOB_URL", rootUrl+j.getUrl());
}
String root = jenkins.getRootDir().getPath();
env.put("JENKINS_HOME", root);
env.put("HUDSON_HOME", root); // legacy compatibility
Thread t = Thread.currentThread();
if (t instanceof Executor) {
Executor e = (Executor) t;
env.put("EXECUTOR_NUMBER", String.valueOf(e.getNumber()));
if (e.getOwner() instanceof MasterComputer) {
env.put("NODE_NAME", "master");
} else {
env.put("NODE_NAME", e.getOwner().getName());
}
Node n = e.getOwner().getNode();
if (n != null)
env.put("NODE_LABELS", Util.join(n.getAssignedLabels(), " "));
}
}
}
代码示例来源:origin: jenkinsci/jenkins
j.getRootUrl(), Util.escape(l.getName()), l.getUrl(), l.getNodes().size(), l.getClouds().size())
);
代码示例来源:origin: jenkinsci/jenkins
/**
* Exposes the name/value as an environment variable.
*/
@Override
public void buildEnvironment(Run<?,?> build, EnvVars env) {
Run run = getRun();
String value = (null == run) ? "UNKNOWN" : Jenkins.getInstance().getRootUrl() + run.getUrl();
env.put(name, value);
env.put(name + ".jobName", getJobName()); // undocumented, left for backward compatibility
env.put(name + "_JOBNAME", getJobName()); // prefer this version
env.put(name + ".number" , getNumber ()); // same as above
env.put(name + "_NUMBER" , getNumber ());
// if run is null, default to the standard '#1' display name format
env.put(name + "_NAME", (null == run) ? "#" + getNumber() : run.getDisplayName()); // since 1.504
String buildResult = (null == run || null == run.getResult()) ? "UNKNOWN" : run.getResult().toString();
env.put(name + "_RESULT", buildResult); // since 1.517
env.put(name.toUpperCase(Locale.ENGLISH),value); // backward compatibility pre 1.345
}
内容来源于网络,如有侵权,请联系作者删除!