Jenkins の Email-ext を使用すると、Jelly メール テンプレートを作成できます。毎回ビルドをトリガーせずに、どのように作成してテストしますか? 基本的に、Jelly スクリプトを変更し、ブラウザーで更新を押すと、ハードコード プロジェクトとビルド結果に基づいてテンプレートが自動的にレンダリングされる 1 秒の反復を探しています。
9323 次
2 に答える
7
_http://server/script/ で Jenkins スクリプト コンソールを開きます (これが実際の URL である場合、Stackoverflow で編集を保存する際に問題が発生します)。
your-project-name
次のコードを入力し、プロジェクトの名前とme@me.com
電子メール アドレスに置き換えます。
import hudson.model.StreamBuildListener
import hudson.plugins.emailext.ExtendedEmailPublisher
import java.io.ByteArrayOutputStream
def projectName = "your-project-name"
def project = Jenkins.instance.getItem(projectName)
try
{
def testing = Jenkins.instance.copy(project, "$projectName-Testing")
def build = project.lastUnsuccessfulBuild
// see the <a href="http://javadoc.jenkins-ci.org/hudson/model/Job.html#getLastBuild()" title="Job" target="_blank">javadoc for the Job class</a> for other ways to get builds
def baos = new ByteArrayOutputStream()
def listener = new StreamBuildListener(baos)
testing.publishersList.each() { p ->
println(p)
if(p instanceof ExtendedEmailPublisher) {
// modify the properties as necessary here
p.recipientList = 'me@me.com' // set the recipient list while testing
// run the publisher
p.perform((AbstractBuild<?,?>)build, null, listener)
// print out the build log from ExtendedEmailPublisher
println(new String( baos.toByteArray(), "UTF-8" ))
}
}
}
finally
{
if (testing != null)
{
testing.delete()
}
}
ソース: https://earl-of-code.com/2013/02/prototyping-and-testing-groovy-email-templates/
これを簡単にするために追跡する問題もあります。
于 2013-02-27T16:48:32.283 に答える
7
プラグインのより新しいバージョンのビルドに対してテンプレートをテストするオプションが追加されました。ジョブの画面では、左側に [Email Template Testing] というリンクが表示されます。ビルドを選択して再度テストすると、テンプレートがすぐにレンダリングされます。
于 2014-12-05T20:12:05.703 に答える