Reputation: 353
In Jenkins, I am using ‘Validation String Parameter’ as one input parameter ‘COMPANY_NAME’.
I need to get it in groovy script in Build secion. Using the below code, I am unable to get the my custom build parameter.
import hudson.model.*
def companyName= System.getenv(“COMPANY_NAME”)
It returns null. How to get Jenkins build parameters in the Groovy script?
Upvotes: 2
Views: 8998
Reputation: 353
I got it. It worked using the below groovy code.
Working Code
def build = this.getProperty('binding').getVariable('build')
def listener = this.getProperty('binding').getVariable('listener')
def env = build.getEnvironment(listener)
println "COMPANY_NAME = "+ env.COMPANY_NAME
Referred - Access to build environment variables from a groovy script in a Jenkins build step (Windows)
Upvotes: 0