I added a few log messages to track the progress of a build and discovered 
that buildEnvVars is called several times.  I doubt this hurts anything, 
but it seems this could be optimized some.

Feb 22, 2016 2:56:26 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: ENTER

Feb 22, 2016 2:56:26 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: Setting GIT_BRANCH: origin/master

Feb 22, 2016 2:56:26 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: LocalBranch configured as: null

Feb 22, 2016 2:56:26 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: Setting GIT_LOCAL_BRANCH: master

Feb 22, 2016 2:56:26 PM 
net.uaznia.lukanus.hudson.plugins.gitparameter.GitParameterDefinition 
generateContents

INFO: generateContents contenttype PT_BRANCH RemoteConfig 
[file:///Users/mgiroux/understanding-jenkins]

Feb 22, 2016 2:56:30 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: ENTER

Feb 22, 2016 2:56:30 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: Setting GIT_BRANCH: origin/master

Feb 22, 2016 2:56:30 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: LocalBranch configured as: null

Feb 22, 2016 2:56:30 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: Setting GIT_LOCAL_BRANCH: master

Feb 22, 2016 2:56:30 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: ENTER

Feb 22, 2016 2:56:30 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: Setting GIT_BRANCH: origin/master

Feb 22, 2016 2:56:30 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: LocalBranch configured as: null

Feb 22, 2016 2:56:30 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: Setting GIT_LOCAL_BRANCH: master

Feb 22, 2016 2:56:30 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: ENTER

Feb 22, 2016 2:56:30 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: Setting GIT_BRANCH: origin/master

Feb 22, 2016 2:56:30 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: LocalBranch configured as: null

Feb 22, 2016 2:56:30 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: Setting GIT_LOCAL_BRANCH: master

Feb 22, 2016 2:56:30 PM hudson.plugins.git.GitSCM checkout

INFO: Setting GIT_BRANCH: origin/master

Feb 22, 2016 2:56:30 PM hudson.plugins.git.GitSCM checkout

INFO: LocalBranch configured as: null

Feb 22, 2016 2:56:30 PM hudson.plugins.git.GitSCM checkout

INFO: Setting GIT_LOCAL_BRANCH: master

Feb 22, 2016 2:56:31 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: ENTER

Feb 22, 2016 2:56:31 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: Setting GIT_BRANCH: origin/master

Feb 22, 2016 2:56:31 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: LocalBranch configured as: null

Feb 22, 2016 2:56:31 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: Setting GIT_LOCAL_BRANCH: master

Feb 22, 2016 2:56:31 PM hudson.model.Run execute

INFO: DefaultEnvironmentReport #22 main build action completed: SUCCESS

Feb 22, 2016 2:56:31 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: ENTER

Feb 22, 2016 2:56:31 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: Setting GIT_BRANCH: origin/master

Feb 22, 2016 2:56:31 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: LocalBranch configured as: null

Feb 22, 2016 2:56:31 PM hudson.plugins.git.GitSCM buildEnvVars

INFO: Setting GIT_LOCAL_BRANCH: master




On Monday, February 22, 2016 at 2:43:17 PM UTC-7, Michael Giroux wrote:
>
> I'm looking to add a new environment variable to expose the LocalBranch 
> name as GIT_LOCAL_BRANCH.  I'm looking at the code in GitSCM.checkout and 
> am not able to figure out why GIT_BRANCH is being set twice.
>
> GIT_BRANCH is set first when checkout sets environment:
>
>         EnvVars environment = build.getEnvironment(listener);
>
> This call results in a call to GitSCM.buildEnvVars which will set 
> GIT_BRANCH.
>
> A few lines later, GitSCM.checkout tests GIT_BRANCH again:
>
>         environment.put(GIT_COMMIT, revToBuild.revision.getSha1String());
>
>         Branch branch = Iterables.getFirst(revToBuild.revision
> .getBranches(),null);
>
>         if (branch != null && branch.getName() != null) { // null for a 
> detached HEAD
>
>             environment.put(GIT_BRANCH, getBranchName(branch));
>
>         }
>
> Do I need to set my new variable GIT_LOCAL_BRANCH in checkout AND 
> buildEnvVars, or can I get by with setting it only in checkout?
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/b5668284-b5b3-4147-ad23-b63ec1a9ba74%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to