[
https://issues.jenkins-ci.org/browse/JENKINS-13119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=160374#comment-160374
]
gbois edited comment on JENKINS-13119 at 3/18/12 9:51 AM:
----------------------------------------------------------
I added the ability to evaluate a Groovy script in 'Prepare environment for the
build' section
For example, you can have the following script:
if (CASE==null){
return null;
}
def stringValue="StRinG";
if ("upper".equals(CASE)){
def map = [COMPUTE_VAR: stringValue.toUpperCase()]
return map
}
if ("lower".equals(CASE)){
def map = [COMPUTE_VAR: stringValue.toLowerCase()]
return map
}
This script injects the environment COMPUTE_VAR in the following job steps.
As you can see, this variable is computed according the CASE variable value.
This variable comes from a parameter value (given by the user).
The only restrictions are:
- The script has to be in Groovy (close to Jenkins core, written in Java/Groovy)
- The script has to return a Map Java object (all the map elements will
exported as environment variables).
Please upgrade to EnvInject 1.38.
Let me know if it suits you.
was (Author: gbois):
I added the ability to evaluate a Groovy script in 'Prepare environment for
the build' section
For example, you can have the following script:
if (CASE==null){
return null;
}
def stringValue="StRinG";
if ("upper".equals(CASE)){
def map = [COMPUTE_VAR: stringValue.toUpperCase()]
return map
}
if ("lower".equals(CASE)){
def map = [COMPUTE_VAR: stringValue.toLowerCase()]
return map
}
This script injects the environment COMPUTE_VAR in the following job steps.
As you see, this variable is computed according the CASE variable value.
This variable comes from a parameter value (given by the user).
The only restrictions are:
- The script has to be in Groovy (close to Jenkins core, written in Java/Groovy)
- The script has to return a Map Java object (all the map elements will
exported as environment variables).
Please upgrade to EnvInject 1.38.
Let me know if it suits you.
> How can I set an environment variable based on value of user passed parameter?
> ------------------------------------------------------------------------------
>
> Key: JENKINS-13119
> URL: https://issues.jenkins-ci.org/browse/JENKINS-13119
> Project: Jenkins
> Issue Type: Improvement
> Components: envinject
> Affects Versions: current
> Environment: Redhat Linux 5.5
> Reporter: suresh kukalakuntla
> Assignee: gbois
>
> I want to set value for an environment variable based on user provided input
> during the build and use this env variable to set workspace in a jenkins
> project.
> Ex: User has to select MODULE_NAME when performing a build. MODULE_NAME is a
> choice parameter. Based on the value selected by the user I want to set
> MODULE_FOLDER environment variable and use it for setting the WORKSPACE.
> Below is the functionality I am expecting.
> if MODULE_NAME is 'A' then set MODULE_FOLDER = FOLDER1
> else if MODULE_NAME is 'B' then set MODULE_FOLDER = FOLDER2
> else if MODULE_NAME is 'C' then set MODULE_FOLDER = FOLDER3
> Now set WORKSPACE=/usr/modules/$MODULE_FOLDER
> Please help me achieve this functionality. I want to have only one job for
> all modules. Based on the module user selects I want to build it and deploy
> it.
> your guidance is much appreciated
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.jenkins-ci.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira