How to pass the jelly email template dynamically from workspace

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.

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

Welcome back, @Sarvabhowma1995 . :wave:

In Jenkins, the Email Extension Plugin by default looks for Jelly scripts in the $JENKINS_HOME/email-templates directory.

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

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. :thinking:

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’ step to do this:
    def jellyScript = readFile 'path/to/your/jelly/script.jelly'
  2. Then, you could use the emailext step 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:
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. :person_facepalming:

My bad, sorry. :person_shrugging: