Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-2413

[Email plugin] Read parameters/variables used during build

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Component/s: email-ext-plugin
    • Labels:
      None
    • Environment:
      Platform: All, OS: All
    • Similar Issues:

      Description

      One of the parameters I want to set on some of the projects is "who to email
      results to". Unfortunately the email plugin:

      http://hudson.gotdns.com/wiki/display/JENKINS/Email-ext+plugin

      Cannot read environment variables or project parameters that were set by
      someone. Would be nice if it could.

        Attachments

          Issue Links

            Activity

            akshay_abd akshay_abd created issue -
            mindless Alan Harder made changes -
            Field Original Value New Value
            Component/s email-ext [ 15538 ]
            Component/s other [ 15490 ]
            Hide
            ashlux ashlux added a comment -

            What do you mean "environment variables or project parameters that were set by
            someone"?

            Show
            ashlux ashlux added a comment - What do you mean "environment variables or project parameters that were set by someone"?
            Hide
            asalicetti asalicetti added a comment -

            I understand what akshay_abd means because I have the same problem.

            It seems to be impossible to use build parameters defined on build as tokens.

            For example, on the same job where I use the email-ext plugin, I have defined PROJECT_BUILD_NAME as build parameter, but when I use $PROJECT_BUILD_NAME, it does not print the value has defined during build, instead it prints parameter name.
            I've also tried to use ${ENV, PROJECT_BUILD_NAME}, ${ENV.PROJECT_BUILD_NAME} and $ENV.PROJECT_BUILD_NAME, but no one worked.

            Show
            asalicetti asalicetti added a comment - I understand what akshay_abd means because I have the same problem. It seems to be impossible to use build parameters defined on build as tokens. For example, on the same job where I use the email-ext plugin, I have defined PROJECT_BUILD_NAME as build parameter, but when I use $PROJECT_BUILD_NAME, it does not print the value has defined during build, instead it prints parameter name. I've also tried to use ${ENV, PROJECT_BUILD_NAME}, ${ENV.PROJECT_BUILD_NAME} and $ENV.PROJECT_BUILD_NAME, but no one worked.
            Hide
            asalicetti asalicetti added a comment -

            You should reference the parameter you defined (or the environment variable) with the following syntax:
            ${ENV,var="PARAMETER_NAME_UPPERCASE"}

            For example, if you defined as parameter MYPAR you can use it into your message / subject of email-ext as:
            ${ENV,var="MYPAR"}

            Show
            asalicetti asalicetti added a comment - You should reference the parameter you defined (or the environment variable) with the following syntax: ${ENV,var="PARAMETER_NAME_UPPERCASE"} For example, if you defined as parameter MYPAR you can use it into your message / subject of email-ext as: ${ENV,var="MYPAR"}
            asalicetti asalicetti made changes -
            Fix Version/s current [ 10162 ]
            Assignee asalicetti [ asalicetti ]
            Resolution Fixed [ 1 ]
            Status Open [ 1 ] Resolved [ 5 ]
            ashlux ashlux made changes -
            Link This issue is duplicated by JENKINS-5322 [ JENKINS-5322 ]
            rajpra rajpra made changes -
            Link This issue is duplicated by JENKINS-3605 [ JENKINS-3605 ]
            mdonohue mdonohue made changes -
            Link This issue is duplicated by JENKINS-3605 [ JENKINS-3605 ]
            abayer Andrew Bayer made changes -
            Status Resolved [ 5 ] Closed [ 6 ]
            Hide
            nonshatter lloyd roles added a comment -

            Why is it that we can't use a build parameter in the recipient field? I've tried similar combo's to those documented above by asalicetti

            Show
            nonshatter lloyd roles added a comment - Why is it that we can't use a build parameter in the recipient field? I've tried similar combo's to those documented above by asalicetti
            rtyler R. Tyler Croy made changes -
            Workflow JNJira [ 132486 ] JNJira + In-Review [ 201447 ]
            Hide
            avreimale Avraham Kahana added a comment -

             This issue & its duplicate 5322 were both closed, while it was not clearly stated whether the issue was solved. 

            In any case, I am trying the different alternatives proposed above and still, none of them work.

            Show
            avreimale Avraham Kahana added a comment -  This issue & its duplicate 5322 were both closed, while it was not clearly stated whether the issue was solved.  In any case, I am trying the different alternatives proposed above and still, none of them work.
            Hide
            scarlson scott carlson added a comment -

            I have also tried several ways and nothing seems to work.  The duplicate may be closed since it was referring to documentation but I believe this issue needs to be re-opened unless someone can confirm it works with the current build.  

            Show
            scarlson scott carlson added a comment - I have also tried several ways and nothing seems to work.  The duplicate may be closed since it was referring to documentation but I believe this issue needs to be re-opened unless someone can confirm it works with the current build.  
            Hide
            guillertal Guillermo Martinez added a comment -

            Still not solved, I want to use an Environment Variable as the recipient.

            Show
            guillertal Guillermo Martinez added a comment - Still not solved, I want to use an Environment Variable as the recipient.
            Hide
            pyrocks Mor L added a comment - - edited

            Environment variables can be referenced like this (at least for pipeline jobs):

            ${build.environment['PARAM_NAME']}

            It works for me, at least in the email body when using SCRIPT (did not test with JELLY_SCRIPT).

            It works for environment variables and job parameters which jenkins exposes as env variables.

            It does not work for env variables set after the build started for example using env.PARAM="value".

            I also confirmed that the suggested syntax does not work.

             

            I hope this helps
            Mor

            Show
            pyrocks Mor L added a comment - - edited Environment variables can be referenced like this (at least for pipeline jobs): ${build.environment ['PARAM_NAME'] } It works for me, at least in the email body when using SCRIPT (did not test with JELLY_SCRIPT). It works for environment variables and job parameters which jenkins exposes as env variables. It does not work for env variables set after the build started for example using env.PARAM="value". I also confirmed that the suggested syntax does not work .   I hope this helps Mor
            Hide
            guillertal Guillermo Martinez added a comment -

            Mor L in the body it works, but not in the recipient list.

            Show
            guillertal Guillermo Martinez added a comment - Mor L in the body it works, but not in the recipient list.
            Hide
            pyrocks Mor L added a comment -

            Guillermo Martinez If you use pipeline to send the email - then I do not see the problem. If you do not use pipeline, well... I guess I can't help.

            Show
            pyrocks Mor L added a comment - Guillermo Martinez  If you use pipeline to send the email - then I do not see the problem. If you do not use pipeline, well... I guess I can't help.
            Hide
            scarlson scott carlson added a comment -

            This is with the pipeline.  It is a problem with the recipient list in the pipeline.  I haven't tried it since my last post but I assume its in the same state.  Anywhere else your method works Guillermo Martinez, just not in the recipient list.

            Show
            scarlson scott carlson added a comment - This is with the pipeline.  It is a problem with the recipient list in the pipeline.  I haven't tried it since my last post but I assume its in the same state.  Anywhere else your method works Guillermo Martinez , just not in the recipient list.
            Hide
            pyrocks Mor L added a comment - - edited

            scott carlson I fail to see why you have problems with pipeline - since pipeline has env available to you - you don't need a special syntax.

            So this would be like:

            emailext body: 'A Test EMail', subject: 'Test', to: env.YOUR_PARAM

            Am I missing something?

            Show
            pyrocks Mor L added a comment - - edited scott carlson  I fail to see why you have problems with pipeline - since pipeline has env available to you - you don't need a special syntax. So this would be like: emailext body:  'A Test EMail' , subject:  'Test' , to:  env.YOUR_PARAM Am I missing something?
            Hide
            scarlson scott carlson added a comment -

            In all other instances in pipeline it works fine.. it is only with the "to:" section specifically there is an error.  every other instance in the body, subject, etc. it works fine.

            For sanity I have tried 

            • to: env.PARAM
            • to: ${build.environment['PARAM']}
            • to: "${env.PARAM}"
            • to: "${build.environment['PARAM']}

            none of them worked. 

            If you are able could you try to use it in the "to:" section?

             

            Show
            scarlson scott carlson added a comment - In all other instances in pipeline it works fine.. it is only with the "to:" section specifically there is an error.  every other instance in the body, subject, etc. it works fine. For sanity I have tried  to: env.PARAM to: ${build.environment ['PARAM'] } to: "${env.PARAM}" to: "${build.environment ['PARAM'] } none of them worked.  If you are able could you try to use it in the "to:" section?  
            Hide
            pyrocks Mor L added a comment -

            scott carlson

            Not sure what is wrong with your setup - but it works. Tested with the following code (job has a single parameter called PARAM1 with value someone@somewhere.com):

            node {
                echo env.PARAM1
                emailext body: "body",
                         subject: "subject",
                         to: env.PARAM1
            }
            

            output:

            Started by user myuser
            [Pipeline] node
            Running on somenode in F:\somefolder
            [Pipeline] {
            [Pipeline] echo
            someone@somewhere.com
            [Pipeline] emailext
            Sending email to: someone@somewhere.com
            [Pipeline] }
            [Pipeline] // node
            [Pipeline] End of Pipeline
            Finished: SUCCESS
            
            Show
            pyrocks Mor L added a comment - scott carlson Not sure what is wrong with your setup - but it works. Tested with the following code (job has a single parameter called PARAM1 with value someone@somewhere.com): node { echo env.PARAM1 emailext body: "body" , subject: "subject" , to: env.PARAM1 } output: Started by user myuser [Pipeline] node Running on somenode in F:\somefolder [Pipeline] { [Pipeline] echo someone@somewhere.com [Pipeline] emailext Sending email to: someone@somewhere.com [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline Finished: SUCCESS
            Hide
            stodorov Steve Todorov added a comment -

            It simply doesn't work as expected. Having this in the emailext body just doesn't work:

             

            <p>Build #$BUILD_NUMBER ran on ${env.NODE_NAME} ${build.environment['NODE_NAME']} and terminated with $BUILD_STATUS.</p>
            

            It prints to something like this in the sent email:

             

            Build #54 ran on ${env.NODE_NAME} ${build.environment['NODE_NAME']} and terminated with Still Failing.

            I've tried pretty much all combinations I've seen on the internet and the documentation. None of them work as expected - they will either print as empty or will print "as-is" without being replaced (like in the example above). 

            Mor L's  example works, though.

            Show
            stodorov Steve Todorov added a comment - It simply doesn't work as expected. Having this in the emailext body just doesn't work:   <p>Build #$BUILD_NUMBER ran on ${env.NODE_NAME} ${build.environment[ 'NODE_NAME' ]} and terminated with $BUILD_STATUS.</p> It prints to something like this in the sent email:   Build #54 ran on ${env.NODE_NAME} ${build.environment[ 'NODE_NAME' ]} and terminated with Still Failing. I've tried pretty much all combinations I've seen on the internet and the documentation. None of them work as expected - they will either print as empty or will print "as-is" without being replaced (like in the example above).  Mor L's  example works, though.
            Hide
            lsbwant lsb want added a comment -

            not work for me too

            Show
            lsbwant lsb want added a comment - not work for me too

              People

              Assignee:
              asalicetti asalicetti
              Reporter:
              akshay_abd akshay_abd
              Votes:
              3 Vote for this issue
              Watchers:
              9 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: