Your msbuild script can access environment variables set by Jenkins, as you mention.
If you see a non-empty environment variable named:
GIT_COMMIT
: that means there is a Git repository associated to your job
SVN_REVISION
: that means there is a SVN repository associated to your job
CVS_BRANCH
: that means there is a CVS repository associated to your job
More complex approach:
As in this groovy script, you can check:
if there is any scm defined for a job
scm = project.scm;
if that scm is Git or another SCM (like the Mercurial one)
if (scm instanceof hudson.plugins.git.GitSCM) {
From there, your groovy script can inject in your job a new environment variable (with the JENKINS EnvInject Plugin)
import hudson.model.*
def build = Thread.currentThread().executable
def pa = new ParametersAction([
new StringParameterValue("SCM", "Git")
])
build.addAction(pa)
The OP Idothisallday asks in the comments:
How is above var better than using SVN_URL
and GIT_URL
?
This is the same general idea. The second approach let you define your own value), but to the general question "Want to know if there is a better way.": no, not really (that I know of).