简体   繁体   中英

How to get Jenkins build parameters in the Groovy script?

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM