I have several environment variables defined for a project on jenkins, amongst which i want to incorporate some onto the email notification sent before and after build success. But groovy.text.Templat

Accessing Variables Specified for Jenkins Groovy Plugin Script

When writing a script that is run by Jenkins Groovy Plugin as a build step (Execute System Groovy Script) one can specify ‘variable bindings’. The helpline says: Define varibale bingings (in the prope

How can I access Jenkins build artifacts from the groovy Postbuild plugin?

Is there a way to read a build artifact file using the Groovy postbuild plugin? Some context: I have written some testng tests that are run by maven in Jenkins. Jenkins runs the tests, gives me the te

Pass parameter from build step to post-build step in Jenkins

How can I pass a parameter in Jenkins from a build step to post-build step? I don’t want to do it through a file, as it’s just a simple string (version number) that I want to pass. In post-build I use

Answers

The Scriptler Groovy script doesn’t seem to get all the environment variables of the build. But what you can do is force them in as parameters to the script:

When you add the Scriptler build step into your job, select the option “Define script parameters”

Add a parameter for each environment variable you want to pass in. For example “Name: JOB_NAME”, “Value: $JOB_NAME”. The value will get expanded from the Jenkins build environment using ‘$envName’ type variables, most fields in the job configuration settings support this sort of expansion from my experience.

In your script, you should have a variable with the same name as the parameter, so you can access the parameters with something like:

println “JOB_NAME = $JOB_NAME”

I haven’t used Sciptler myself apart from some experimentation, but your question posed an interesting problem. I hope this helps!