I ran into the same problem and decided to unlock the Multiple SCM plugin to fix it: https://github.com/JakeStoeffler/multiple-scms-plugin
If you want, just clone my repo and run mvn to build an HPI file (located in target/multiple-scms.hpi ) that you can manually download and install in Jenkins. If you prefer to customize yourself, immediately copy the source repo , open MultiSCM.java and replace the code in the buildEnvVars() method with something like the following:
@Override public void buildEnvVars(AbstractBuild<?,?> build, Map<String, String> env) { // Add each SCM env vars, appending indices where needed to avoid collisions for (int i = 0; i < scms.size(); i++) { try { EnvVars currScmVars = new EnvVars(); scms.get(i).buildEnvVars(build, currScmVars); for (Entry<String, String> entry : currScmVars.entrySet()) { if (env.containsKey(entry.getKey())) { // We have a collision; append the index of this SCM to the env var name env.put(entry.getKey() + "_" + i, entry.getValue()); } else { // No collision; just put the var as usual env.put(entry.getKey(), entry.getValue()); } } } catch(NullPointerException npe) {} } }
Hope the comments here are pretty clear. Basically, the error in the source code is that when you have multiple SCMs with the same environment variable names, the variables are overwritten as they repeat. We work around this by preventing these overwrites and instead add an index to the variable name.
Here is an example of how to use it: if 3 Git SCM is configured in our project, now we can access the last commit hash of each Git repository using env vars GIT_COMMIT , GIT_COMMIT_1 , and GIT_COMMIT_2 . The attached indexes correspond to the SCM order in the project configuration in Jenkins.
Obviously this is a quick and dirty solution, but it works for what I need to do. Feel free to customize it according to your needs.
Jake stoeffler
source share