mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-14 12:32:15 +00:00
Honor $JENKINS_HOME.
Honor $JENKINS_HOME (just like we used to do $HUDSON_HOME) We still fall back to $HUDSON_HOME every step of the way for maximum backward compatibility. I wasn't initially planning to do this for the first version, but working on native packages made me think we should deliver this.
This commit is contained in:
1 parent
62100264ac
commit
8ea876faa4
13 files changed
+65
-48
No files matched your search
@@ -64,7 +64,7 @@ public class Main {
|
||||
public static int run(String[] args) throws Exception {
|
||||
String home = getHudsonHome();
|
||||
if (home==null) {
|
||||
System.err.println("HUDSON_HOME is not set.");
|
||||
System.err.println("JENKINS_HOME is not set.");
|
||||
return -1;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
@@ -76,7 +76,9 @@ public class Main {
|
||||
}
|
||||
|
||||
private static String getHudsonHome() {
|
||||
return EnvVars.masterEnvVars.get("HUDSON_HOME");
|
||||
String home = EnvVars.masterEnvVars.get("JENKINS_HOME");
|
||||
if (home!=null) return home;
|
||||
return EnvVars.masterEnvVars.get("JENKINS_HOME");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -261,36 +261,46 @@ public final class WebAppMain implements ServletContextListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the home directory for Hudson.
|
||||
* Determines the home directory for Jenkins.
|
||||
*
|
||||
* <p>
|
||||
* We look for a setting that affects the smallest scope first, then bigger ones later.
|
||||
*
|
||||
* <p>
|
||||
* People makes configuration mistakes, so we are trying to be nice
|
||||
* with those by doing {@link String#trim()}.
|
||||
*/
|
||||
private File getHomeDir(ServletContextEvent event) {
|
||||
// check JNDI for the home directory first
|
||||
try {
|
||||
InitialContext iniCtxt = new InitialContext();
|
||||
Context env = (Context) iniCtxt.lookup("java:comp/env");
|
||||
String value = (String) env.lookup("HUDSON_HOME");
|
||||
if(value!=null && value.trim().length()>0)
|
||||
return new File(value.trim());
|
||||
// look at one more place. See issue #1314
|
||||
value = (String) iniCtxt.lookup("HUDSON_HOME");
|
||||
if(value!=null && value.trim().length()>0)
|
||||
return new File(value.trim());
|
||||
} catch (NamingException e) {
|
||||
// ignore
|
||||
for (String name : HOME_NAMES) {
|
||||
try {
|
||||
InitialContext iniCtxt = new InitialContext();
|
||||
Context env = (Context) iniCtxt.lookup("java:comp/env");
|
||||
String value = (String) env.lookup(name);
|
||||
if(value!=null && value.trim().length()>0)
|
||||
return new File(value.trim());
|
||||
// look at one more place. See issue #1314
|
||||
value = (String) iniCtxt.lookup(name);
|
||||
if(value!=null && value.trim().length()>0)
|
||||
return new File(value.trim());
|
||||
} catch (NamingException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
// next the system property
|
||||
for (String name : HOME_NAMES) {
|
||||
String sysProp = System.getProperty(name);
|
||||
if(sysProp!=null)
|
||||
return new File(sysProp.trim());
|
||||
}
|
||||
|
||||
// finally check the system property
|
||||
String sysProp = System.getProperty("HUDSON_HOME");
|
||||
if(sysProp!=null)
|
||||
return new File(sysProp.trim());
|
||||
|
||||
// look at the env var next
|
||||
String env = EnvVars.masterEnvVars.get("HUDSON_HOME");
|
||||
if(env!=null)
|
||||
return new File(env.trim()).getAbsoluteFile();
|
||||
for (String name : HOME_NAMES) {
|
||||
String env = EnvVars.masterEnvVars.get(name);
|
||||
if(env!=null)
|
||||
return new File(env.trim()).getAbsoluteFile();
|
||||
}
|
||||
|
||||
// otherwise pick a place by ourselves
|
||||
|
||||
@@ -304,8 +314,11 @@ public final class WebAppMain implements ServletContextListener {
|
||||
return ws;
|
||||
}
|
||||
|
||||
// if for some reason we can't put it within the webapp, use home directory.
|
||||
return new File(new File(System.getProperty("user.home")),".hudson");
|
||||
File legacyHome = new File(new File(System.getProperty("user.home")), ".hudson");
|
||||
if (legacyHome.exists())
|
||||
return legacyHome; // before rename, this is where it was stored
|
||||
|
||||
return new File(new File(System.getProperty("user.home")), ".jenkins");
|
||||
}
|
||||
|
||||
public void contextDestroyed(ServletContextEvent event) {
|
||||
@@ -320,4 +333,6 @@ public final class WebAppMain implements ServletContextListener {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(WebAppMain.class.getName());
|
||||
|
||||
|
||||
private static final String[] HOME_NAMES = {"JENKINS_HOME","HUDSON_HOME"};
|
||||
}
|
||||
@@ -31,7 +31,7 @@ import org.jvnet.animal_sniffer.IgnoreJRERequirement;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Periodically checks the disk usage of <tt>HUDSON_HOME</tt>,
|
||||
* Periodically checks the disk usage of <tt>JENKINS_HOME</tt>,
|
||||
* and activate {@link HudsonHomeDiskUsageMonitor} if necessary.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
@@ -49,12 +49,12 @@ public class HudsonHomeDiskUsageChecker extends PeriodicWork {
|
||||
long total = Hudson.getInstance().getRootDir().getTotalSpace();
|
||||
if(free<=0 || total<=0) {
|
||||
// information unavailable. pointless to try.
|
||||
LOGGER.info("HUDSON_HOME disk usage information isn't available. aborting to monitor");
|
||||
LOGGER.info("JENKINS_HOME disk usage information isn't available. aborting to monitor");
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
LOGGER.fine("Monitoring disk usage of HUDSON_HOME. total="+total+" free="+free);
|
||||
LOGGER.fine("Monitoring disk usage of JENKINS_HOME. total="+total+" free="+free);
|
||||
|
||||
|
||||
// if it's more than 90% full and less than the minimum, activate
|
||||
@@ -63,7 +63,7 @@ public class HudsonHomeDiskUsageChecker extends PeriodicWork {
|
||||
HudsonHomeDiskUsageMonitor.get().activated = (total/free>10 && free< FREE_SPACE_THRESHOLD);
|
||||
} catch (LinkageError _) {
|
||||
// pre Mustang
|
||||
LOGGER.info("Not on JDK6. Cannot monitor HUDSON_HOME disk usage");
|
||||
LOGGER.info("Not on JDK6. Cannot monitor JENKINS_HOME disk usage");
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Monitors the disk usage of <tt>HUDSON_HOME</tt>, and if it's almost filled up, warn the user.
|
||||
* Monitors the disk usage of <tt>JENKINS_HOME</tt>, and if it's almost filled up, warn the user.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
@@ -90,13 +90,13 @@ public final class HudsonHomeDiskUsageMonitor extends AdministrativeMonitor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension point for suggesting solutions for full HUDSON_HOME.
|
||||
* Extension point for suggesting solutions for full JENKINS_HOME.
|
||||
*
|
||||
* <h3>Views</h3>
|
||||
* <dl>
|
||||
* <dt>message.jelly</dt>
|
||||
* <dd>
|
||||
* This view is rendered inside an LI tag as a possible solution to the full HUDSON_HOME problem.
|
||||
* This view is rendered inside an LI tag as a possible solution to the full JENKINS_HOME problem.
|
||||
* </dd>
|
||||
* </dl>
|
||||
*/
|
||||
|
||||
@@ -32,7 +32,7 @@ public class InitStrategy {
|
||||
* Returns the list of *.hpi and *.hpl to expand and load.
|
||||
*
|
||||
* <p>
|
||||
* Normally we look at {@code $HUDSON_HOME/plugins/*.hpi} and *.hpl.
|
||||
* Normally we look at {@code $JENKINS_HOME/plugins/*.hpi} and *.hpl.
|
||||
*
|
||||
* @return
|
||||
* never null but can be empty. The list can contain different versions of the same plugin,
|
||||
|
||||
@@ -2363,7 +2363,7 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
|
||||
pluginManager.stop();
|
||||
|
||||
if(getRootDir().exists())
|
||||
// if we are aborting because we failed to create HUDSON_HOME,
|
||||
// if we are aborting because we failed to create JENKINS_HOME,
|
||||
// don't try to save. Issue #536
|
||||
getQueue().save();
|
||||
|
||||
@@ -2917,7 +2917,7 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds /userContent/... to $HUDSON_HOME/userContent.
|
||||
* Binds /userContent/... to $JENKINS_HOME/userContent.
|
||||
*/
|
||||
public DirectoryBrowserSupport doUserContent() {
|
||||
return new DirectoryBrowserSupport(this,getRootPath().child("userContent"),"User content","folder.gif",true);
|
||||
|
||||
@@ -1771,8 +1771,8 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
|
||||
env.put("JOB_URL", rootUrl+getParent().getUrl());
|
||||
}
|
||||
|
||||
if(!env.containsKey("HUDSON_HOME"))
|
||||
env.put("HUDSON_HOME", Hudson.getInstance().getRootDir().getPath() );
|
||||
env.put("JENKINS_HOME", Hudson.getInstance().getRootDir().getPath() );
|
||||
env.put("HUDSON_HOME", Hudson.getInstance().getRootDir().getPath() ); // legacy compatibility
|
||||
|
||||
Thread t = Thread.currentThread();
|
||||
if (t instanceof Executor) {
|
||||
|
||||
@@ -62,14 +62,14 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Encourages the user to migrate HUDSON_HOME on a ZFS file system.
|
||||
* Encourages the user to migrate JENKINS_HOME on a ZFS file system.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
* @since 1.283
|
||||
*/
|
||||
public class ZFSInstaller extends AdministrativeMonitor implements Serializable {
|
||||
/**
|
||||
* True if $HUDSON_HOME is a ZFS file system by itself.
|
||||
* True if $JENKINS_HOME is a ZFS file system by itself.
|
||||
*/
|
||||
private final boolean active = shouldBeActive();
|
||||
|
||||
@@ -302,7 +302,7 @@ public class ZFSInstaller extends AdministrativeMonitor implements Serializable
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrates $HUDSON_HOME to a new ZFS file system.
|
||||
* Migrates $JENKINS_HOME to a new ZFS file system.
|
||||
*
|
||||
* TODO: do this in a separate JVM to elevate the privilege.
|
||||
*
|
||||
|
||||
@@ -42,7 +42,7 @@ import java.lang.management.ManagementFactory;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Makes sure that no other Hudson uses our <tt>HUDSON_HOME</tt> directory,
|
||||
* Makes sure that no other Hudson uses our <tt>JENKINS_HOME</tt> directory,
|
||||
* to forestall the problem of running multiple instances of Hudson that point to the same data directory.
|
||||
*
|
||||
* <p>
|
||||
|
||||
@@ -33,13 +33,13 @@ import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Controls how a {@link HudsonTestCase} initializes <tt>HUDSON_HOME</tt>.
|
||||
* Controls how a {@link HudsonTestCase} initializes <tt>JENKINS_HOME</tt>.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public interface HudsonHomeLoader {
|
||||
/**
|
||||
* Returns a directory to be used as <tt>HUDSON_HOME</tt>
|
||||
* Returns a directory to be used as <tt>JENKINS_HOME</tt>
|
||||
*
|
||||
* @throws Exception
|
||||
* to cause a test to fail.
|
||||
|
||||
@@ -84,7 +84,7 @@ public class TestPluginManager extends PluginManager {
|
||||
}
|
||||
|
||||
// and pick up test dependency *.hpi that are placed by maven-hpi-plugin TestDependencyMojo.
|
||||
// and copy them into $HUDSON_HOME/plugins.
|
||||
// and copy them into $JENKINS_HOME/plugins.
|
||||
URL index = getClass().getResource("/test-dependencies/index");
|
||||
if (index!=null) {// if built with maven-hpi-plugin < 1.52 this file won't exist.
|
||||
BufferedReader r = new BufferedReader(new InputStreamReader(index.openStream(),"UTF-8"));
|
||||
|
||||
@@ -36,7 +36,7 @@ import static java.lang.annotation.ElementType.METHOD;
|
||||
* Runs a test case with a data set local to test method or the test class.
|
||||
*
|
||||
* <p>
|
||||
* This recipe allows your test case to start with the preset <tt>HUDSON_HOME</tt> data loaded
|
||||
* This recipe allows your test case to start with the preset <tt>JENKINS_HOME</tt> data loaded
|
||||
* either from your test method or from the test class.
|
||||
*
|
||||
* <p>
|
||||
@@ -47,12 +47,12 @@ import static java.lang.annotation.ElementType.METHOD;
|
||||
* <ol>
|
||||
* <li>
|
||||
* Under <tt>org/acme/FooTest/testBar</tt> directory (that is, you'll have
|
||||
* <tt>org/acme/FooTest/testBar/config.xml</tt>), in the same layout as in the real <tt>HUDSON_HOME</tt> directory.
|
||||
* <tt>org/acme/FooTest/testBar/config.xml</tt>), in the same layout as in the real <tt>JENKINS_HOME</tt> directory.
|
||||
* <li>
|
||||
* In <tt>org/acme/FooTest/testBar.zip</tt> as a zip file.
|
||||
* <li>
|
||||
* Under <tt>org/acme/FooTest</tt> directory (that is, you'll have
|
||||
* <tt>org/acme/FooTest/config.xml</tt>), in the same layout as in the real <tt>HUDSON_HOME</tt> directory.
|
||||
* <tt>org/acme/FooTest/config.xml</tt>), in the same layout as in the real <tt>JENKINS_HOME</tt> directory.
|
||||
* <li>
|
||||
* In <tt>org/acme/FooTest.zip</tt> as a zip file.
|
||||
* </ol>
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.lang.annotation.Target;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Runs a test case with one of the preset HUDSON_HOME data set.
|
||||
* Runs a test case with one of the preset JENKINS_HOME data set.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
* @see LocalData
|
||||
|
||||
Reference in new issue
Block a user