JENKINS_HOME是Jenkins的主目錄。java
在Jenkins上查看JENKINS_HOME:git
系統管理→系統設置→主目錄 (<JENKINS_URL>/configure頁面)github
如上圖幫助文檔所示:web
Jenkins儲存全部的數據文件在這個目錄下. 你能夠經過如下幾種方式更改:
ide
使用你Web容器的管理工具設置JENKINS_HOME環境參數.工具
在啓動Web容器以前設置JENKINS_HOME環境變量.this
(不推薦)更改Jenkins.war(或者在展開的Web容器)內的web.xml配置文件.spa
這個值在Jenkins運行時是不能更改的. 其一般用來確保你的配置是否生效.日誌
查看Jenkins的WEB-INF/web.xml,能夠得知Jenkins主對象爲hudson.WebAppMain:code
查看WebAppMain.java的源碼,getHomeDir方法即用來肯定Jenkins的主目錄,其邏輯以下:
鑑於Hudson是Jenkins的前身,因此爲了兼容Jenkins主目錄的名稱有:JENKINS_HOME或HUDSON_HOME
private static final String[] HOME_NAMES = {"JENKINS_HOME","HUDSON_HOME"};
首先,會在JNDI(可在web.xml配置文件中配置)中查找JENKINS_HOME或HUDSON_HOME
其次會在系統屬性中查找JENKINS_HOME或HUDSON_HOME
接着會在環境變量中查找JENKINS_HOME或HUDSON_HOME
最後,若是上述都找不到,會默認選擇 $user.home/.jenkins爲JENKINS_HOME($user.home/.hudson爲HUDSON_HOME)
附:WebAppMain.java的getHomeDir方法源碼
/** * 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()}. * * <p> * @return the File alongside with some description to help the user troubleshoot issues */ public FileAndDescription getHomeDir(ServletContextEvent event) { // check JNDI for the home directory first 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 FileAndDescription(new File(value.trim()),"JNDI/java:comp/env/"+name); // look at one more place. See issue #1314 value = (String) iniCtxt.lookup(name); if(value!=null && value.trim().length()>0) return new FileAndDescription(new File(value.trim()),"JNDI/"+name); } catch (NamingException e) { // ignore } } // next the system property for (String name : HOME_NAMES) { String sysProp = System.getProperty(name); if(sysProp!=null) return new FileAndDescription(new File(sysProp.trim()),"System.getProperty(\""+name+"\")"); } // look at the env var next for (String name : HOME_NAMES) { String env = EnvVars.masterEnvVars.get(name); if(env!=null) return new FileAndDescription(new File(env.trim()).getAbsoluteFile(),"EnvVars.masterEnvVars.get(\""+name+"\")"); } // otherwise pick a place by ourselves String root = event.getServletContext().getRealPath("/WEB-INF/workspace"); if(root!=null) { File ws = new File(root.trim()); if(ws.exists()) // Hudson <1.42 used to prefer this before ~/.hudson, so // check the existence and if it's there, use it. // otherwise if this is a new installation, prefer ~/.hudson return new FileAndDescription(ws,"getServletContext().getRealPath(\"/WEB-INF/workspace\")"); } File legacyHome = new File(new File(System.getProperty("user.home")),".hudson"); if (legacyHome.exists()) { return new FileAndDescription(legacyHome,"$user.home/.hudson"); // before rename, this is where it was stored } File newHome = new File(new File(System.getProperty("user.home")),".jenkins"); return new FileAndDescription(newHome,"$user.home/.jenkins"); }
此外,在Tomcat/logs/stdout_YYYYMMDD.log中有以下日誌:
Jenkins home directory: F:\JENKINS_HOME found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
這與getHomeDir方法的相應源碼對應:
System.out.println("Jenkins home directory: "+home+" found at: "+describedHomeDir.description);