Home > Software design >  Jenkins Error after upgrade - "Not all environment variables could be successfully injected.&qu
Jenkins Error after upgrade - "Not all environment variables could be successfully injected.&qu

Time:09-22

After the upgrade from Jenkins "1.651.3" to "2.346.3 LTS".

My job log contains this message many times:
ERROR: Not all environment variables could be successfully injected. Check for similarly-named environment variables.

There is no clue. How to find which variables could not be successfully injected?

CodePudding user response:

I found that message goes from Environment Injector plugin

It goes from class EnvInjectEnvVarsContributor

And it seems that it is not an error. It is just a warning, that some property, already exists in environment variables. Responsilbe commit from history

Map<String, String> result = jobPropertyInfo.getPropertiesContentMap(env);
if (result != null) {
    int expectedEnvSize = env.size()   result.size();
    env.putAll(result);
    if (env.size() != expectedEnvSize) {
        listener.error("Not all environment variables could be successfully injected. "  
                "Check for similarly-named environment variables.");
    }
}

To find which properties are confilicting I used this groovy script executed in the job like "Execute system Groovy script"

import hudson.model.*
import org.jenkinsci.plugins.envinject.EnvInjectJobProperty 
import jenkins.model.Jenkins

println "FIND CONFLICTING PROPERTIES GROOVY SCRIPT---------------------------- START" 
def job = Hudson.instance.getJob('my_job')
println job
EnvInjectJobProperty jobProperty = (EnvInjectJobProperty) job.getProperty(EnvInjectJobProperty.class);
def jobPropertyInfo = jobProperty.getInfo();
def env = Jenkins.instance.getGlobalNodeProperties()[0].getEnvVars() 
Map<String, String> result = jobPropertyInfo.getPropertiesContentMap(env);
println "RESULT"
println result
println result.size()

println "ENV"
println env
println env.size()

println "FIND CONFLICTING PROPERTIES GROOVY SCRIPT---------------------------- END" 

Maybe it will help to someone.

  • Related