# How to pass the jelly email template dynamically from workspace

**URL:** <https://community.jenkins.io/t/how-to-pass-the-jelly-email-template-dynamically-from-workspace/13135>\
**Category:** Using Jenkins\
**Tags:** question, plugin-site, pipeline\
**Created:** [March 7, 2024, 9:33pm UTC](https://community.jenkins.io/t/how-to-pass-the-jelly-email-template-dynamically-from-workspace/13135 "2024-03-07T21:33:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sarvabhowma1995](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/sarvabhowma1995/32/2038_2.png) [@Sarvabhowma1995](https://community.jenkins.io/u/Sarvabhowma1995)\
**Post date:** [March 7, 2024, 9:33pm UTC](https://community.jenkins.io/t/how-to-pass-the-jelly-email-template-dynamically-from-workspace/13135/1 "2024-03-07T21:33:47Z")

</div>

Jenkins setup:  
I would like to check if there’s any way we can send Jelly email templates dynamically from a custom location instead of saving them under the jenkins\_home/email-templates directory. I have attached my test Groovy file, and please use the default jelly file from the email extension plugin document.

> <https://github.com/jenkinsci/email-ext-plugin/blob/9592cea4e68636e9cddf360ff294051982c4572b/src/main/resources/hudson/plugins/emailext/templates/html.jelly>

[jenkins.groovy](https://community.jenkins.io/uploads/short-url/8d3JlhXtQM61mBfhZNgUqKayLCe.groovy) (895 Bytes)

I tried loading a file and using that variable; however, it’s actually not displaying the details from the jelly file; instead, it’s just showing the static HTML content.

---

<div class="post-metadata">

**Author:** ![poddingue](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/poddingue/32/985_2.png) [@poddingue](https://community.jenkins.io/u/poddingue)\
**Post date:** [March 11, 2024, 4:55pm UTC](https://community.jenkins.io/t/how-to-pass-the-jelly-email-template-dynamically-from-workspace/13135/2 "2024-03-11T16:55:14Z")

</div>

Welcome back, @Sarvabhowma1995 . 👋

In Jenkins, the [Email Extension Plugin](https://plugins.jenkins.io/email-ext/) by default looks for Jelly scripts in the `$JENKINS_HOME/email-templates` [directory](https://plugins.jenkins.io/email-ext/#plugin-content-jelly-script-content-templates).

I thought for a split second I had a solution, but alas, I have the same issue, this would only work for static content. 😢

However, here is what I wrote before realizing it could not work this way:  
You could try to use a custom location for your Jelly scripts by loading the file content into a variable and then using that variable in the email step. 🤔

Here’s how I see it:

1. First, you would need to read the Jelly script file from your custom location and store its content in a variable. You could use the [‘readFile’](https://www.jenkins.io/doc/pipeline/steps/workflow-basic-steps/#readfile-read-file-from-workspace) step to do this:  
`def jellyScript = readFile 'path/to/your/jelly/script.jelly'`
2. Then, you could use the [`emailext` step](https://www.jenkins.io/doc/pipeline/steps/email-ext/#emailext-extended-email) to send the email. In the body parameter, you could use the `${SCRIPT, template="<your_script>"}` token to include the content of the Jelly script.  
Here’s an example from the top of my head:

```auto
emailext body: '''${SCRIPT, template="${jellyScript}"}''',
         mimeType: 'text/html',
         subject: 'Your Subject',
         to: 'your@email.com'

```

I think this would only work for static content, and not for dynamic content. 🤦

My bad, sorry. 🤷
