[groovy] Creating a Jenkins environment variable using Groovy

On my side it only worked this way by replacing an existing parameter.

def artifactNameParam = new StringParameterValue('CopyProjectArtifactName', 'bla bla bla')
build.replaceAction(new ParametersAction(artifactNameParam))

Additionally this script must be run with system groovy.

A groovy must be manually installed on that system and the bin dir of groovy must be added to path. Additionally in the lib folder I had to add jenkins-core.jar.

Then it was possible to modify a parameter in a groovy script and get the modified value in a batch script after to continue work.