2017-08-14 41 views
0

我喜歡將我的Jenkins電子郵件腳本提交給我的工作副本,並將其用於Email-ext。如何更改Email-ext插件以從自定義位置加載腳本

所以我寫了類似:

pipeline { 
    agent any 
    stages { 
     stage('Build') { 
      steps { 
       echo 'Building...' 
      } 
     } 
    } 
    post { 
     always { 
      echo 'Sending email...' 
      emailext body: '''${SCRIPT, template="${WORKSPACE}\\Src\\Scripts\\Jenkins\\groovy-html2.template"}''', 
      mimeType: 'text/html', 
      subject: "[Leeroy Jenkins] ${currentBuild.fullDisplayName}", 
      to: "[email protected]", 
      replyTo: "[email protected]", 
      recipientProviders: [[$class: 'CulpritsRecipientProvider']] 
     } 
    } 
} 

但我得到以下郵箱: Groovy的模板文件[$ {WORKSPACE} SrcScriptsJenkinsgroovy-html2.template在$ JENKINS_HOME /電子郵件模板沒有被發現。

回答

0

通過手動重寫使用命令行該文件解決它:

pipeline { 
    agent any 
    stages { 
     stage('Build') { 
      steps { 
       echo 'Building...' 
      } 
     } 
    } 
    post { 
     always { 
      echo 'Sending email...' 

      bat "copy /Y ${WORKSPACE}\\Src\\Scripts\\Jenkins\\groovy-html2.template \"${JENKINS_HOME}\\email-templates\\groovy-html2.template\"" 

      emailext body: '''${SCRIPT, template="${WORKSPACE}\\Src\\Scripts\\Jenkins\\groovy-html2.template"}''', 
      mimeType: 'text/html', 
      subject: "[Leeroy Jenkins] ${currentBuild.fullDisplayName}", 
      to: "[email protected]", 
      replyTo: "[email protected]", 
      recipientProviders: [[$class: 'CulpritsRecipientProvider']] 
     } 
    } 
} 

有點粗糙,但它的工作原理。

1

出於安全原因,模板必須位於正確的目錄中。如果你想把它們保存在SCM中,我建議你創建一個Jenkins作業來檢查SCM到正確的目錄。從技術上講,雖然該目錄不應該是可寫的,但可能是。或者,您可以使用管道中的groovy代碼本身

+0

確定它是出於安全原因?有一個公開的問題:[JENKINS-43903](https://issues.jenkins-ci.org/browse/JENKINS-43903) – user3360767

+0

是的,我是插件的維護者。 –

+0

我已關閉該票作爲wontfix。 –

相關問題