does this https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob-environmentVariables-groovy actually work?
Probably more of an plugin issue.
groovy scripts