Using Jenkins EMail-ext plugin how to send the content of a file

229 Views Asked by At

Using the EMail-ext plugin, how can we send the content of a file which is stored in a variable using def fileContent = readFile "filePath"

pipeline {
    agent {
        label 'test'
    }
    tools {
        jdk 'JDK_HOME'
        maven 'MAVEN_HOME'
    }
stages {
     stage('clean') {
        steps {
            script {
                sh 'mvn clean'
            }
        }
    }
    stage('check server status') {
        steps {
            script{
                sh 'mvn verify'
            }
        }
    }
}
post{
  success{
 def fileDetails = readFile "./EnvironmentLinks.txt"
 def linesInFile = fileDetails.readLines()
 emailext to: "${env.DEFAULT_MAIL_LIST}",
 mimeType: 'text/html',
 from: "[email protected]",
 attachmentsPattern: '**/html-report/*.html',
 subject: "Test Email",
 body: """
<p style=font-family:calibri;font-size:15px>Hi - This is a test email </p>
<p style=font-family:calibri;font-size:13.7px;><b>File Details:</b><br>
${linesInFile}</p>
}
}

linesInFile returns a list. And in the email, its getting displayed as below:

Hi - This is a test email File Details: [Test1,Test2,Test3]

But what I am expecting is :
Hi - This is a test email
File Details:
Test1
Test2
Test3

Any help/suggestions in this regard?

0

There are 0 best solutions below