When setting an environment variable, the variable is accessible in shell but not in a Jenkins plugin. For example, if I use the following pipeline
doStuff is not able to access $GITUSER, but the shell command is able to do so.
This has been discussed by https://stackoverflow.com/questions/65015553/accessing-jenkins-set-environment-variables-from-a-jenkins-plugin and https://stackoverflow.com/questions/14214249/jenkins-plugin-environment-variables but nobody knew a solution.
I've created a mwe: https://github.com/DaGeRe/example-no-environment With everything I tried in https://github.com/DaGeRe/example-no-environment/blob/main/src/main/java/de/example/DoStuffBuilder.java I was not able to get the environment variable (a workaround would be to print the environment to a file and read this file in the plugin, but this does not seem to be a clean solution for me).
I am not sure whether this is a bug or missing documentation, but I did not find anything about injection of environment variables to own plugins in https://www.jenkins.io/doc/developer/plugin-development/ or related documentation.