加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

How to read the environment variables in groovy email templa

发布时间:2020-12-14 16:40:47 所属栏目:大数据 来源:网络整理
导读:down vote If you are using the email-ext Jenkins plugin to send out emails,there is a "build" object that contains a lot of information about your Jenkins job. I would do the following: Print out the properties inside this object by adding



down vote

If you are using the email-ext Jenkins plugin to send out emails,there is a "build" object that contains a lot of information about your Jenkins job.

I would do the following:

  1. Print out the properties inside this object by adding the following code to your template:

    <% println build.properties.collect{it}.join('<br />') %>

  2. View the email template output. You can either use the Jenkins "Email Template Testing" feature or just run your job. You should see a whole bunch of "KEY=VALUE" print outs.

  3. Look for the environment variable you are interested in. If your environment variable is listed in?environment={BUILD_NUMBER=45,BUILD_DISPLAY_NAME=#45...},you can just call?build.environment['BUILD_NUMBER']?to get 45.

  4. If you want to inject custom environment variables I would suggest installing the?Env Inject Plugin,defining your variables through that plugin and then looking for the variable in build.envVars

就是说 build这个对象有当前build的很多信息,
但是这个在email groovy template里面怎么引用系统的变量呢
方法一:
<% println build.environment['BUILD_NUMBER'] %>
方法二:
<%=build.environment['BUILD_NUMBER']%>
如:
<td><span class="fail"><%=build.environment[' BUILD_NUMBER']%></span></td>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读