How to send email notification for Maven build

Is there an easy way to send email notifications to Maven for every build without external CI tools, just like Ant?

+3
source share
5 answers

If CI is not an option, I would use a simple shell script:

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

If you decide to use the CI tool, I would highly recommend Hudson. The page shows how easy it is to launch. The continuous integration server sounds pompous and adventurous, but Hudson is dead-simple.

+4
source

I would highly recommend using the CI tool to manage this for you. I personally like to configure which emails to send in the assembly to avoid spam. For example, only notify when an assembly starts to fail or starts working again, and not every time it fails.

If you are sure this is the right approach, you can use the maven-changes-plugin to send email for each build. You can configure the mail template with speed and link the fulfillment of goals to the corresponding phase so that it is sent when you want it.

I also put the configuration in the profile so it was sent when you want it to be (for example, when the profile is active).

The configuration looks something like this:

 <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> 
+2
source

Although the question is a bit older, it is possible that someone still needs a different solution: I created a plugin for this purpose. Take a look at the plugin page on github.com . Multiuser alternative MimeMessages are not implemented (look at the FAQ for reasons), as well as a decent template, but as if you just want to send a text message with attachments, it should do the trick.

I plan to send it to mojo.codehaus.org, hence gId. For now, you must compile it yourself - sorry for the inconvenience.

+1
source

There is also a custom Postman email plugin that gives you options to send test results or even arbitrary html indicating the source file. Here is a good thread explaining how it should be configured.

+1
source

I do not use Maven, but I think you can do it with a plugin .

0
source

Source: https://habr.com/ru/post/1400185/


All Articles