2
votes

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?

1
i would turn that into an answer and mark it correctGraeme

1 Answers

0
votes

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)