模板名称是变量时如何使用Groovy模板引擎? [英] How to use Groovy template engine when template name is a variable?

查看:1124
本文介绍了模板名称是变量时如何使用Groovy模板引擎?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法来使用groovy变量,而不是使用硬编码的模板名称。



当前代码如下所示:'$ {SCRIPT,template =groovy-html.template}'我尝试使用嵌套变量扩展,但仍然出现错误。

示例:

  def body ='''$ {SCRIPT,template =$ {template}}' ''




未找到Groovy模板文件[$ {template}]在
$ JENKINS_HOME / email-templates中。使用text.jelly模板生成。


我的电话可以在 https://github.com/pycontribs/powertape/blob/master/vars/notifyBuild.groovy#L47

解决方案

  def sendEmail(String subject,String template)
{
def bodyContent =\ $ {SCRIPT,template = \$ {template} \}

emailext subject:$ {subject},
body:bodyContent ,
recipientProviders:[[$ class:'RequesterRecipientProvider']]
}

上面的工作适合我。


I am trying to find a way to make use of a groovy variable in stead of using a hardcoded template name

Current code looks like: '${SCRIPT, template="groovy-html.template"}' and I tried to use nested variable expansion but I still got an error.

Example:

def body = '''${SCRIPT, template="${template}"}'''

Groovy Template file [${template}] was not found in $JENKINS_HOME/email-templates. Generated using text.jelly template.

My call can be seen at https://github.com/pycontribs/powertape/blob/master/vars/notifyBuild.groovy#L47

解决方案

def sendEmail(String subject, String template)
{
   def bodyContent = "\${SCRIPT, template=\"${template}\"}"

   emailext  subject: "${subject}",
             body: bodyContent,
             recipientProviders: [[$class: 'RequesterRecipientProvider']]
}

The above worked for me.

这篇关于模板名称是变量时如何使用Groovy模板引擎?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆