2017-07-06 6 views
2

ジョブが正常に実行されたら、Jenking DSL Plugin/Groovyを使用して電子メールを送信しています。コンテンツセクションで Jenkinsジョブからの電子メールの内容としてのビルドログの送信

static void sendEmail(Job job, String jobName) { 
    job.with { 
     publishers { 
      extendedEmail { 
       recipientList('[email protected]') 
       defaultSubject("Jenkins Job started : ${jobName}") 
       defaultContent("See the latest build in the jenkins job here https://jenkins.xyz.com/job/${jobName}/") 
       contentType('text/html') 
       triggers { 
        failure { 
         content("See the latest build in the jenkins job here https://jenkins.xyz.com/job/${jobName}/") 
         contentType('text/html') 
         recipientList('[email protected]') 
         subject("Build Failed in Jenkins: ${jobName}") 
        } 
        success { 
         content('See the latest build in the jenkins job here https://jenkins.xyz.com/job/${jobName}/ <pre> ${BUILD_LOG, maxLines=30, escapeHtml=false} </pre>') 
         contentType('text/html') 
         recipientList('[email protected]') 
         subject("Build Success in Jenkins: ${jobName}") 
        } 
       } 
      } 
     } 
    } 
} 

content('See the latest build in the jenkins job here https://jenkins.xyz.com/job/${jobName}/ <pre> ${BUILD_LOG, maxLines=30, escapeHtml=false} </pre>') 

私は、焦がす引用を使用する場合、私は、電子メールの内容が、やジョブ名としてログオン印刷できると私はその後、二重引用符を使用する場合、私ができジョブ名は印刷しますが、ビルドログは印刷しません。

電子メールにジョブ名とビルドログの両方を印刷するにはどうすればよいですか?

+0

- このように、あなたが使用することができます '「」'と '「」 '必要に応じて。これらの式を使用しているBTWは、せいぜい問題になるようです([here](https://stackoverflow.com/questions/32697156/jenkins-build-log-maxlines-escapehtml-not-working)を参照))。 –

答えて

1

String interpolationは、二重引用符で囲んだ文字列でのみ動作します。したがって、二重引用符に変更してください。 var30がGroovyではなくJenkins自身によって展開されているのではなく、BUILD_LOGの展開がその後に機能しないと言うと、したがって、次の試してください。

content("See the latest build in the jenkins job here https://jenkins.xyz.com/job/${jobName}/ " + '<pre> ${BUILD_LOG, maxLines=30, escapeHtml=false} </pre>') 

か、$脱出:あなたは離れて文字列を分割し、それを連結するとどうなりますか

content("See the latest build in the jenkins job here https://jenkins.xyz.com/job/${jobName}/ <pre> \${BUILD_LOG, maxLines=30, escapeHtml=false} </pre>") 
関連する問題