1

I need include email content from html file using email-ext plugin in jenkins pipeline (my jenkins is 2.24 version), i try this

emailext (
  subject: "some subject",
  body: "${FILE,path="enteryPath/template.html"}",
  to: "email@example.com"
)  

but dont work for me :( any suggestions or solution?? , thanks advance.

Yolanda Lopez
  • 163
  • 2
  • 8
  • Possible duplicate of [How to attach files to Jenkins Pipeline notification](https://stackoverflow.com/questions/41422526/how-to-attach-files-to-jenkins-pipeline-notification) – Vitalii Vitrenko Jul 19 '17 at 22:03

4 Answers4

2

You can use attachmentsPattern parameter.

emailext (
  subject: "some subject",
  body: "${FILE,path="enteryPath/template.html"}",
  to: "email@example.com"
  attachmentsPattern: 'enteryPath/template.html'
)  
Vitalii Vitrenko
  • 9,763
  • 4
  • 43
  • 62
  • Where to place in my html file ? – vijay Nov 24 '17 at 06:07
  • 1
    @vijay you can place it anywhere where Jenkins has read permissions. – Vitalii Vitrenko Nov 24 '17 at 08:57
  • @VitaliiVitrenko, lets say template.html has an tag on it? how are we going to define it? using the image snippet here doesnt work for me. any thoughts? – PANDA MAN Jul 13 '20 at 05:28
  • @PANDAMAN I believe you should use some sort of hosting for the image instead of store it on Jenkins machine. But this is really out of scope for this question. Please create another one or search existing. – Vitalii Vitrenko Jul 13 '20 at 09:52
0

Can't you store the body in the workspace? And then just run:

emailext (
  subject: "some subject",
  body: readFileFromWS("enteryPath/template.html"),
  to: "email@example.com"
) 

But this would mean the body is static from job-creation and forward, guess you want it to be read when the mail should be sent?

MaTePe
  • 936
  • 1
  • 6
  • 11
0
    stage ('email'){
    steps{
      script{
             echo "hello"
             emailext (subject: "some subject", body: '${FILE,path="template.html"}',to: "xyz@gmail.com")  

            }
        }       
  }

Install the email-ext plugin for Jenkins and you can have the above code to send emails as part of the stage and path here would be relative to Jenkins workspace.

Dragonthoughts
  • 2,180
  • 8
  • 25
  • 28
0

You could make use of readFile()

emailext (
            mimeType: 'text/html',
            to: "sample@email.com",
            attachLog: true,
            subject: 'Subject Line',
            body: readFile("path/to/html/file")
        )

readFile will read it as stream of strings and hands it over to emailext plugin, hence if you might have used any special variables such as

${BUILD_NUMBER}

${BUILD_LOG_REGEX}

will get compiled correctly and replaced with interpreted values.

Nishabu
  • 134
  • 1
  • 15