且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法访问电子邮件正文中的环境变量

更新时间:2022-12-03 10:42:17

emailext 插件管道方法将使用Groovy变量.因此,您需要从 env 对象: env.MODEL 中将环境变量作为键访问.此外,您需要在JP/Groovy解释器中插入字符串,这需要使用双引号进行解析,而不是将其转换为文字字符串并在 shell 步骤中使用shell解释器进行解析.方法.此外,使用 $ {} 语法来精确定义用于插值的变量名称更为安全.

The emailext plugin pipeline method will expect Groovy variables. Therefore, you would need to access environment variables as keys from within the env object: env.MODEL. Additionally, you would need to interpolate the string within the JP/Groovy interpreter, which would require resolving with the double quotes, as opposed to casting as a literal string and resolving with the shell interpreter in a shell step method for example. Additionally, it is safer to use the ${} syntax to precisely define the variable name for interpolation.

有趣的是,您为 subject 参数正确地完成了这两项操作,但是更改了 body 的语法,因此它无法正常工作.

Interestingly enough, you are doing both of these correctly for the subject argument, but have changed your syntax for the body, and therefore it is not working.

结合这些修补程序:

body: """<html>
  <p><b>Regression Test Report</b></p>
  <p>${env.MODEL}</p>
  <p>Build URL: ${env.BUILD_URL}</p>
  <p>Build Status: ${env.BUILD_STATUS}</p>                        
  <br />
  <p><b>Console Output</b></p>
  <pre>${BUILD_LOG_REGEX, regex='^.*test session starts.*$', showTruncatedLines=false}</pre>
  <pre>${BUILD_LOG_EXCERPT, start='^.*test.*==$', end='^.*in.*==$'}</pre>
  ...
  </html>"""