Quantcast

[JIRA] (JENKINS-13119) How can I set an environment variable based on value of user passed parameter?

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[JIRA] (JENKINS-13119) How can I set an environment variable based on value of user passed parameter?

JIRA noreply@jenkins-ci.org
suresh kukalakuntla created JENKINS-13119:
---------------------------------------------

             Summary: 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

       
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[JIRA] (JENKINS-13119) How can I set an environment variable based on value of user passed parameter?

JIRA noreply@jenkins-ci.org

    [ https://issues.jenkins-ci.org/browse/JENKINS-13119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=160371#comment-160371 ]

SCM/JIRA link daemon commented on JENKINS-13119:
------------------------------------------------

Code changed in jenkins
User: Gregory Boissinot
Path:
 src/main/java/hudson/plugins/envfile/EnvFileBuildWrapper.java
 src/main/java/hudson/plugins/setenv/SetEnvBuildWrapper.java
 src/main/java/org/jenkinsci/plugins/envinject/EnvInjectJobPropertyInfo.java
 src/main/java/org/jenkinsci/plugins/envinject/EnvInjectListener.java
 src/main/java/org/jenkinsci/plugins/envinject/service/EnvInjectEnvVars.java
 src/main/java/org/jenkinsci/plugins/envinject/service/EnvInjectScriptExecutor.java
 src/main/resources/org/jenkinsci/plugins/envinject/EnvInjectJobProperty/config.jelly
 src/main/resources/org/jenkinsci/plugins/envinject/EnvInjectJobProperty/help-groovyScriptContent.html
 src/main/resources/org/jenkinsci/plugins/envinject/EnvInjectJobProperty/help-keepBuildVariables.html
 src/main/webapp/help.html
 src/test/java/org/jenkinsci/plugins/envinject/EnvInjectBuildWrapperTest.java
http://jenkins-ci.org/commit/envinject-plugin/257acc17f1ae1560f95270d1c24aebc6b60d0261
Log:
  Fix JENKINS-13119





               

> 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

       
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[JIRA] (JENKINS-13119) How can I set an environment variable based on value of user passed parameter?

JIRA noreply@jenkins-ci.org
In reply to this post by JIRA noreply@jenkins-ci.org

     [ https://issues.jenkins-ci.org/browse/JENKINS-13119?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

gbois resolved JENKINS-13119.
-----------------------------

    Resolution: Fixed

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

       
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[JIRA] (JENKINS-13119) How can I set an environment variable based on value of user passed parameter?

JIRA noreply@jenkins-ci.org
In reply to this post by JIRA noreply@jenkins-ci.org

    [ 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

       
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[JIRA] (JENKINS-13119) How can I set an environment variable based on value of user passed parameter?

JIRA noreply@jenkins-ci.org
In reply to this post by JIRA noreply@jenkins-ci.org

    [ https://issues.jenkins-ci.org/browse/JENKINS-13119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=160383#comment-160383 ]

gbois commented on JENKINS-13119:
---------------------------------

And for your need, you have to select a custom workspace and use your computed variable.
               

> 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

       
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[JIRA] (JENKINS-13119) How can I set an environment variable based on value of user passed parameter?

JIRA noreply@jenkins-ci.org
In reply to this post by JIRA noreply@jenkins-ci.org

    [ https://issues.jenkins-ci.org/browse/JENKINS-13119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=160423#comment-160423 ]

suresh kukalakuntla commented on JENKINS-13119:
-----------------------------------------------

Thank You so much Greg for your quick response, with a plugin update!!!

I installed EnvInject 1.38, added similar groovy script to my job and tried to build it. I got the below error.

[EnvInject] - Preparing an environment for the build.
[EnvInject] - [ERROR] - SEVERE ERROR occurs: com/sun/xml/internal/ws/server/UnsupportedMediaException

I think I have to add required jar to class path of JBOSS AS 7 I am using for jenkins, which I do not know how to. I am trying to find out how to do that. Could you please let me know how to do that, if you already know about it?

I will provide an update once I am able to successfully use the updated plugin to set environment variables based on user input.

Thank You once again for your effort.


               

> 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

       
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[JIRA] (JENKINS-13119) How can I set an environment variable based on value of user passed parameter?

JIRA noreply@jenkins-ci.org
In reply to this post by JIRA noreply@jenkins-ci.org

    [ https://issues.jenkins-ci.org/browse/JENKINS-13119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=160428#comment-160428 ]

gbois commented on JENKINS-13119:
---------------------------------

Maybe a JBOSS issue with Groovy.
Do you have the ability to test on another servlet container such as Tomcat?
               

> 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

       
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[JIRA] (JENKINS-13119) How can I set an environment variable based on value of user passed parameter?

JIRA noreply@jenkins-ci.org
In reply to this post by JIRA noreply@jenkins-ci.org

    [ https://issues.jenkins-ci.org/browse/JENKINS-13119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=160429#comment-160429 ]

suresh kukalakuntla commented on JENKINS-13119:
-----------------------------------------------

I am able to to put the required jar file in the lib folder of jenkins.war and I am able to use ENVInject successfully.

Right now I am trying to test Evaluated Groovy script. Tried the below and got and error

[EnvInject] - Evaluation the following Groovy script content:
if (MODULE_NAME==null){ return null; }

if ("ACCT".equals(MODULE_NAME)){ def map = ["MODULE_HOME": "SSP-AM"] return map }

if ("FPD".equals(MODULE_NAME)){ def map = ["MODULE_HOME": "SSP-FPD"] return map }

[EnvInject] - [ERROR] - SEVERE ERROR occurs: startup failed:
Script1.groovy: 3: expecting '}', found 'return' @ line 3, column 70.
   p = ["MODULE_HOME": "SSP-AM"] return map
                                 ^

1 error
               

> 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

       
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[JIRA] (JENKINS-13119) How can I set an environment variable based on value of user passed parameter?

JIRA noreply@jenkins-ci.org
In reply to this post by JIRA noreply@jenkins-ci.org

    [ https://issues.jenkins-ci.org/browse/JENKINS-13119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=160431#comment-160431 ]

suresh kukalakuntla commented on JENKINS-13119:
-----------------------------------------------

Greg,
    I am able to successfully run the groovy script that serves my purpose. I really appreciate your help and time. You are very responsive and quick:)


Below is the log. MODULE_NAME is provided by user when performing build.


[EnvInject] - Evaluation the following Groovy script content:
if(MODULE_NAME.equals('ACCT'))
{
def map = ["MODULE_HOME": "SSP-AM"]

return map;
}

if(MODULE_NAME.equals('FPD'))
{
def map = ["MODULE_HOME": "SSP-FPD"]

return map;
}


Building in workspace /usr/J2EE/JENKINS/jobs/TEST_GROOVY/workspace
[workspace] $ /bin/sh -xe /tmp/hudson50466.sh
+ echo MODULE_NAME:FPD
MODULE_NAME:FPD
+ echo MODULE_HOME:SSP-FPD
MODULE_HOME:SSP-FPD
Finished: SUCCESS
               

> 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

       
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[JIRA] (JENKINS-13119) How can I set an environment variable based on value of user passed parameter?

JIRA noreply@jenkins-ci.org
In reply to this post by JIRA noreply@jenkins-ci.org

    [ https://issues.jenkins-ci.org/browse/JENKINS-13119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=160434#comment-160434 ]

gbois commented on JENKINS-13119:
---------------------------------

Try to use return line

Copy paste the following script, it should work

if (MODULE_NAME==null){ return null; }

if ("ACCT".equals(MODULE_NAME)){
  def map = [MODULE_HOME: "SSP-AM"]
  return map
}

if ("FPD".equals(MODULE_NAME)){
  def map = [MODULE_HOME: "SSP-FPD"]
  return map
}

               

> 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

       
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[JIRA] (JENKINS-13119) How can I set an environment variable based on value of user passed parameter?

JIRA noreply@jenkins-ci.org
In reply to this post by JIRA noreply@jenkins-ci.org

    [ https://issues.jenkins-ci.org/browse/JENKINS-13119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=160435#comment-160435 ]

gbois commented on JENKINS-13119:
---------------------------------

Wiki removes return line.
Otherwise, add a semicolon, for example:

if (MODULE_NAME==null){ return null; }

if ("ACCT".equals(MODULE_NAME)){ def map = [MODULE_HOME: "SSP-AM"] ; return map }

if ("FPD".equals(MODULE_NAME)){ def map = [MODULE_HOME: "SSP-FPD"] ; return map }

               

> 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

       
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[JIRA] (JENKINS-13119) How can I set an environment variable based on value of user passed parameter?

JIRA noreply@jenkins-ci.org
In reply to this post by JIRA noreply@jenkins-ci.org

I have this groovy script:

if (BUILD_TYPE.equals('Trunk')) { def map = [SVN_REPO_PATH: "trunk/ConfigManagement"]; return map; }
if (BUILD_TYPE.equals('Branches')) {
def map = [SVN_REPO_PATH: "branches/${SVN_BRANCH}"]; return map;
}
if (BUILD_TYPE.equals('Tags')) {
def map = [SVN_REPO_PATH: "branches/${SVN_TAG}"]; return map;
}

Where BUILD_TYPE is a CHOICE type user parameter which has Trunk, Branches, Tags in the drop down.

The build keeps failing with,

[EnvInject] - [ERROR] - SEVERE ERROR occurs: No such property: BUILD_TYPE for class: Script1
Finished: FAILURE

Please Help

Change By: Anup Singh (26/Jul/12 10:08 PM)
Resolution: Fixed
Status: Resolved Reopened
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[JIRA] (JENKINS-13119) How can I set an environment variable based on value of user passed parameter?

JIRA noreply@jenkins-ci.org
In reply to this post by JIRA noreply@jenkins-ci.org
Anup Singh commented on Improvement JENKINS-13119

Additional Info: SVN_BRANCH and SVN_TAG are other user input parameters.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[JIRA] (JENKINS-13119) How can I set an environment variable based on value of user passed parameter?

JIRA noreply@jenkins-ci.org
In reply to this post by JIRA noreply@jenkins-ci.org

I suggest you should replacing the condition BUILD_TYPE.equals('Trunk') by "Trunk".equals(BUILD_TYPE).
Inverting the conditions avoids a NullPointerException.
Could apply this principle to all conditions and let me know?

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[JIRA] (JENKINS-13119) How can I set an environment variable based on value of user passed parameter?

JIRA noreply@jenkins-ci.org
In reply to this post by JIRA noreply@jenkins-ci.org
Anup Singh commented on Improvement JENKINS-13119

Gregory, First let me just thank you for such a prompt response. Honestly speaking I am not a big fan of open source mainly because of support. But my view is already changing.

Having said that, I did what you request me and the issue persists. complete details follow:

Started by user Anup Singh
[EnvInject] - Loading node environment variables.
[EnvInject] - Preparing an environment for the build.
[EnvInject] - Keeping Jenkins system variables.
[EnvInject] - Adding build parameters as variables.
[EnvInject] - Evaluation the following Groovy script content:
if ("Trunk".equals(BUILD_TYPE)) { def map = [SVN_REPO_PATH: "trunk/ConfigManagement"]; return map }
if ("Branches".equals(BUILD_TYPE)) {
def map = [SVN_REPO_PATH: "branches/${SVN_BRANCH}"]; return map
}
if ("Tags".equals(BUILD_TYPE)) {
def map = [SVN_REPO_PATH: "branches/${SVN_TAG}"]; return map
}

[EnvInject] - [ERROR] - SEVERE ERROR occurs: No such property: BUILD_TYPE for class: Script1
Finished: FAILURE

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[JIRA] (JENKINS-13119) How can I set an environment variable based on value of user passed parameter?

JIRA noreply@jenkins-ci.org
In reply to this post by JIRA noreply@jenkins-ci.org
Anup Singh commented on Improvement JENKINS-13119

Problem solved...got rid of curly braces around SVN_BRANCH and SVN_TAG. However its weird that I still has to use the $ sign in front of it but I have to use BUILD_TYPE without the preceding $.

if ("Trunk".equals(BUILD_TYPE)) { def map = [SVN_REPO_PATH: "trunk/ConfigManagement"]; return map }
if ("Branches".equals(BUILD_TYPE)) { def map = [SVN_REPO_PATH: "branches/$SVN_BRANCH"]; return map }
if ("Tags".equals(BUILD_TYPE)) { def map = [SVN_REPO_PATH: "tags/$SVN_TAG"]; return map }

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[JIRA] (JENKINS-13119) How can I set an environment variable based on value of user passed parameter?

JIRA noreply@jenkins-ci.org
In reply to this post by JIRA noreply@jenkins-ci.org
Gregory Boissinot resolved Improvement JENKINS-13119 as Fixed
Change By: Gregory Boissinot (30/Jul/12 8:17 PM)
Status: Reopened Resolved
Resolution: Fixed
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
Loading...