Index: src/main/java/hudson/plugins/git/GitPublisher.java =================================================================== --- src/main/java/hudson/plugins/git/GitPublisher.java (revision 19770) +++ src/main/java/hudson/plugins/git/GitPublisher.java (working copy) @@ -1,5 +1,6 @@ package hudson.plugins.git; +import hudson.EnvVars; import hudson.Launcher; import hudson.FilePath.FileCallable; import hudson.model.AbstractBuild; @@ -59,10 +60,20 @@ GitSCM gitSCM = (GitSCM) scm; - IGitAPI git = new GitAPI( + EnvVars environment; + try { + environment = build.getEnvironment(listener); + } catch (IOException e) { + listener.error("IOException publishing in git plugin"); + environment = new EnvVars(); + } catch (InterruptedException e) { + listener.error("IOException publishing in git plugin"); + environment = new EnvVars(); + } + IGitAPI git = new GitAPI( GitSCM.DescriptorImpl.DESCRIPTOR .getGitExe(), build.getProject().getWorkspace(), - listener); + listener, environment); // We delete the old tag generated by the SCM plugin String buildnumber = "hudson-" Index: src/main/java/hudson/plugins/git/SubmoduleCombinator.java =================================================================== --- src/main/java/hudson/plugins/git/SubmoduleCombinator.java (revision 19770) +++ src/main/java/hudson/plugins/git/SubmoduleCombinator.java (working copy) @@ -54,7 +54,7 @@ for (IndexEntry submodule : gitUtils.getSubmodules("HEAD")) { File subdir = new File(workspace, submodule.getFile()); - IGitAPI subGit = new GitAPI(git.getGitExe(), new FilePath(subdir), listener); + IGitAPI subGit = new GitAPI(git.getGitExe(), new FilePath(subdir), listener, git.getEnvironment()); GitUtils gu = new GitUtils(listener, subGit); Collection items = gu.filterTipBranches(gu.getAllBranchRevisions()); @@ -187,7 +187,7 @@ { Revision branch = settings.get(submodule); File subdir = new File(workspace, submodule.getFile()); - IGitAPI subGit = new GitAPI(git.getGitExe(), new FilePath(subdir), listener); + IGitAPI subGit = new GitAPI(git.getGitExe(), new FilePath(subdir), listener, git.getEnvironment()); subGit.checkout(branch.sha1.name()); git.add(submodule.file); Index: src/main/java/hudson/plugins/git/GitAPI.java =================================================================== --- src/main/java/hudson/plugins/git/GitAPI.java (revision 19770) +++ src/main/java/hudson/plugins/git/GitAPI.java (working copy) @@ -1,5 +1,6 @@ package hudson.plugins.git; +import hudson.EnvVars; import hudson.FilePath; import hudson.Launcher; import hudson.FilePath.FileCallable; @@ -34,15 +35,17 @@ FilePath workspace; TaskListener listener; String gitExe; - + EnvVars environment; + public GitAPI(String gitExe, FilePath workspace, - TaskListener listener) { + TaskListener listener, EnvVars environment) { //listener.getLogger().println("Git API @ " + workspace.getName() + " / " + workspace.getRemote() + " - " + workspace.getChannel()); this.workspace = workspace; this.listener = listener; this.gitExe = gitExe; + this.environment = environment; launcher = new LocalLauncher(listener); @@ -52,6 +55,10 @@ return gitExe; } + public EnvVars getEnvironment() { + return environment; + } + public boolean hasGitRepo() throws GitException { try { @@ -99,7 +106,7 @@ } try { - if (launcher.launch(args.toCommandArray(), createEnvVarMap(), + if (launcher.launch(args.toCommandArray(), environment, listener.getLogger(), workspace).join() != 0) { throw new GitException("Failed to fetch"); } @@ -197,7 +204,7 @@ try { - if (launcher.launch(args.toCommandArray(), createEnvVarMap(), fos, + if (launcher.launch(args.toCommandArray(), environment, fos, workspace).join() != 0) { throw new GitException("Error launching git log"); } @@ -248,12 +255,6 @@ launchCommand(args.toCommandArray()); } - protected final Map createEnvVarMap() { - Map env = new HashMap(); - - return env; - } - public void tag(String tagName, String comment) throws GitException { tagName = tagName.replace(' ', '_'); ArgumentListBuilder args = new ArgumentListBuilder(); @@ -287,7 +288,7 @@ try { int status = launcher.launch(args, - createEnvVarMap(), fos, workDir).join(); + environment, fos, workDir).join(); String result = fos.toString(); @@ -495,7 +496,7 @@ ByteArrayOutputStream fos = new ByteArrayOutputStream(); int status = launcher.launch(args.toCommandArray(), - createEnvVarMap(), fos, workspace).join(); + environment, fos, workspace).join(); String result = fos.toString(); Index: src/main/java/hudson/plugins/git/IGitAPI.java =================================================================== --- src/main/java/hudson/plugins/git/IGitAPI.java (revision 19770) +++ src/main/java/hudson/plugins/git/IGitAPI.java (working copy) @@ -1,5 +1,7 @@ package hudson.plugins.git; +import hudson.EnvVars; + import java.io.File; import java.io.IOException; import java.io.OutputStream; @@ -11,7 +13,8 @@ public interface IGitAPI { String getGitExe(); - + EnvVars getEnvironment(); + boolean hasGitRepo() throws GitException; boolean hasGitModules() throws GitException; Index: src/main/java/hudson/plugins/git/GitSCM.java =================================================================== --- src/main/java/hudson/plugins/git/GitSCM.java (revision 19770) +++ src/main/java/hudson/plugins/git/GitSCM.java (working copy) @@ -1,5 +1,6 @@ package hudson.plugins.git; +import hudson.EnvVars; import hudson.FilePath; import hudson.Launcher; import hudson.Proc; @@ -8,6 +9,7 @@ import hudson.model.AbstractProject; import hudson.model.Action; import hudson.model.BuildListener; +import hudson.model.Computer; import hudson.model.Hudson; import hudson.model.Result; import hudson.model.TaskListener; @@ -181,7 +183,13 @@ public Boolean invoke(File localWorkspace, VirtualChannel channel) throws IOException { - IGitAPI git = new GitAPI(gitExe, new FilePath(localWorkspace), listener); + EnvVars environment = new EnvVars(); + try { + environment = Computer.currentComputer().getEnvironment(); + } catch (InterruptedException e) { + listener.error("Interrupted exception getting environment .. trying empty environment"); + } + IGitAPI git = new GitAPI(gitExe, new FilePath(localWorkspace), listener, environment); IBuildChooser buildChooser = new BuildChooser(GitSCM.this,git,new GitUtils(listener,git), buildData ); @@ -239,7 +247,7 @@ File subdir = new File(workspace, submodule.getFile()); IGitAPI subGit = new GitAPI(git.getGitExe(), new FilePath(subdir), - listener); + listener, git.getEnvironment()); subGit.fetch(submoduleRemoteRepository); } catch (Exception ex) { @@ -361,7 +369,13 @@ FilePath ws = new FilePath(localWorkspace); listener.getLogger().println("Checkout:" + ws.getName() + " / " + ws.getRemote() + " - " + ws.getChannel()); - IGitAPI git = new GitAPI(gitExe, ws, listener); + EnvVars environment = new EnvVars(); + try { + environment = build.getEnvironment(listener); + } catch (InterruptedException e) { + listener.error("Interrupted exception getting environment .. using empty environment"); + } + IGitAPI git = new GitAPI(gitExe, ws, listener, environment); if (git.hasGitRepo()) { // It's an update @@ -437,7 +451,14 @@ returnData = workspace.act(new FileCallable() { public Object[] invoke(File localWorkspace, VirtualChannel channel) throws IOException { - IGitAPI git = new GitAPI(gitExe, new FilePath(localWorkspace), listener); + EnvVars environment; + try { + environment = build.getEnvironment(listener); + } catch (Exception e) { + listener.error("Exception reading environment - using empty environment"); + environment = new EnvVars(); + } + IGitAPI git = new GitAPI(gitExe, new FilePath(localWorkspace), listener, environment); IBuildChooser buildChooser = new BuildChooser(GitSCM.this,git,new GitUtils(listener,git), buildData ); @@ -521,7 +542,13 @@ returnData = workspace.act(new FileCallable() { public Object[] invoke(File localWorkspace, VirtualChannel channel) throws IOException { - IGitAPI git = new GitAPI(gitExe, new FilePath(localWorkspace), listener); + EnvVars environment = new EnvVars(); + try { + environment = build.getEnvironment(listener); + } catch (InterruptedException e) { + listener.error("Interrupted exception getting environment .. trying empty environment"); + } + IGitAPI git = new GitAPI(gitExe, new FilePath(localWorkspace), listener, environment); IBuildChooser buildChooser = new BuildChooser(GitSCM.this,git,new GitUtils(listener,git), buildData ); // Straight compile-the-branch