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

[Email plugin] Read parameters/variables used during build

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Major Major
    • email-ext-plugin
    • None
    • Platform: All, OS: All

      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.

          [JENKINS-2413] [Email plugin] Read parameters/variables used during build

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

          Guillermo Martinez added a comment - Still not solved, I want to use an Environment Variable as the recipient.

          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

          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

          pyrocks in the body it works, but not in the recipient list.

          Guillermo Martinez added a comment - pyrocks in the body it works, but not in the recipient list.

          Mor L added a comment -

          guillertal 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.

          Mor L added a comment - guillertal  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.

          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 guillertal, just not in the recipient list.

          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 guillertal , just not in the recipient list.

          Mor L added a comment - - edited

          scarlson 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?

          Mor L added a comment - - edited scarlson  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?

          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?

           

          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?  

          Mor L added a comment -

          scarlson

          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
          

          Mor L added a comment - scarlson 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

          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.

          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.

          lsb want added a comment -

          not work for me too

          lsb want added a comment - not work for me too

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

              Created:
              Updated:
              Resolved: