jenkinsmulti-configuration

Parameterised build in jenkins: Not getting parameters as shell env variables


Jenkins version: 2.6, Linux

Problem: The parameterized build variables are not are not visible (as env variables) in the Execution step "shell script", They used to be visible in the older 1.x jenkins version.

Steps:

  1. Create a parameterized build with a multi configuration project.
  2. Add a parameter to the build (using This project is parameterized-> string parameter, {if that matters} ).
  3. Add a build step "Execute shell" to the job.
  4. Access these parameters in this shell script as env variables.

    echo "++++++++++++ building $lib_name ($lib_version) ++++++++++++++"

To solve this, I have tried to create a groovy script in "Prepare an environment for the run" section. I created env variables using hardcoded values which are pased to shell script as env vars.

def map = ['lib_name':'lib1']
map['lib_version'] = 'master'
return map

But, without hardcoding, I cannot access these variable values even when using solution from How to retrieve Jenkins build parameters using the Groovy API?

I dont know what else has to be done. Can some one please suggest?

---> Updating based on the comments on this question: When I run the following lines in jenkins, I get exception:

def buildVariablesMap = Thread.currentThread().executable.buildVariables 
buildVariablesMap.each{ k, v -> println "${k}:${v}" }




FATAL: No such property: executable for class: hudson.model.OneOffExecutor
groovy.lang.MissingPropertyException: No such property: executable for class: hudson.model.OneOffExecutor
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
    at org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:66)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:296)

Solution

  • This was a bug in jenkins, probably in the credentials plugin: https://issues.jenkins-ci.org/browse/JENKINS-35921

    Thanks for all your help!