Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I list the variables already available inside Jenkinsfile?

I am trying to use some variables like repository name, branch names, build number,... from inside the Jenkinsfile but I am not able to find any documentation regarding this.

Is there a way to print them so I can see what's available? How?

I think it may be related to Printing out variables and values in a Groovy object

Update

this.binding.variables.each {k,v -> println "$k = $v"}

I tried to include the code above but now execution fails with

org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use field groovy.lang.Binding variables
    at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectField(StaticWhitelist.java:177)
like image 437
sorin Avatar asked Apr 01 '16 11:04

sorin


1 Answers

in our case we used the following to get all groovy-defined variables within a jenkinsfile groovy pipeline:

groovyVars = [:] << getBinding().getVariables()
groovyVars.each  {k,v -> print "$k = $v"}
like image 151
DrGecko Avatar answered Oct 14 '22 23:10

DrGecko