4

有没有一种简单的方法可以在没有外部 CI 工具的情况下在 Maven 中为每个构建发送电子邮件通知,就像 Ant 一样?

4

5 回答 5

4

如果 CI 不是一个选项,我会使用一个简单的脚本包装器:

mvn install 2>&1 | tee build.log && cat build.log | mail -s 'Maven build output' user@example.com && rm -f build.log

如果你决定使用 CI 工具,我强烈推荐 Hudson。安装页面显示了它是多么容易运行。持续集成服务器听起来很浮夸和企业化,但 Hudson 非常简单。

于 2009-08-07T14:38:20.417 回答
3

我强烈建议您使用 CI 工具来管理它,我个人喜欢配置要在构建中发送哪些电子邮件以避免垃圾邮件。例如,仅在构建开始失败或重新开始工作时通知,而不是在每次失败时通知。

如果您确定这是正确的方法,您可以使用maven-changes-plugin在每次构建时发送电子邮件。您可以使用 velocity 自定义邮件模板,并将目标的执行绑定到适当的阶段,以便在您需要时发送。

我还将配置放在配置文件中,以便在您想要它时发送(即当配置文件处于活动状态时)。

配置看起来像这样:

<profiles>
  <profile>
    <id>notify</id>
    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-changes-plugin</artifactId>
          <executions>
            <execution>
              <!--send an email in the install phase, 
                could be changed depending on your needs-->
              <phase>install</phase>
              <goals>
                <goal>announcement-mail</goal>
              </goals>
            </execution>
          </executions>
          <configuration>
            <smtpHost>mail.yourhost.com</smtpHost>
            <smtpPort implementation="java.lang.Integer">25</smtpPort>
            <toAddresses>
              <toAddress implementation="java.lang.String">
                someones@email.com</toAddress>
              <toAddress implementation="java.lang.String">
                 someoneelse@email.com</toAddress>
            </toAddresses>
            <!--using a custom velocity template in 
              src/main/resources/mailTemplate/announcement.vm -->
            <template>announcement.vm</template>
            <templateDirectory>mailTemplate</templateDirectory>
          </configuration>
        </plugin>
      </plugins>
    </build>
  </profile>
</profiles>
于 2009-08-07T08:36:58.653 回答
1

虽然问题有点老了,但可能有人仍然需要不同的解决方案:我为此目的创建了一个插件。查看github.com上的插件页面。Multipart-alternative MimeMessages 没有实现(请查看常见问题解答了解原因),以及一个不错的模板,但只要您只是想发送带有附件的文本邮件,它应该可以解决问题。

我计划将它提交给 mojo.codehaus.org,因此是 gId。现在,您必须自己编译它 - 很抱歉给您带来不便。

于 2012-03-27T23:23:06.987 回答
1

There is also a highly customizable Postman mail plugin which gives you options to send test results or even an arbitrary html specifying a source file. Here's a good thread explaining how it should be configured.

于 2013-11-15T14:57:24.043 回答
0

我不使用 Maven,但我认为您可以使用plugin来做到这一点。

于 2009-08-07T07:19:20.137 回答