Reputation: 1448
I have Jenkins job. I run maven java-executor plugin as follows:
compile exec:java
here is the pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.proj.utills</groupId>
<artifactId>db-upgrade</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>com.proj.db.RunMe</mainClass>
<arguments>
<argument>
${TARGET_ENV}
</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>3.0</version>
</dependency>
</dependencies>
</project>
I would like that Jenkins job fail when I got exception in Java code. For now it success even in case of exception. How can I do it? Thanks
Upvotes: 1
Views: 6159
Reputation: 101
I got exactly the same problem and did not like this parsing log solution. For me a -B (to enable the batch mode) did the work nicely
build: - mvn -B deploy
Upvotes: 0
Reputation: 489
You may try the Jenkins Text Finder plugin, downgrade the BUILD status from successful to UNSTABLE/FAIL when the regular expression setting is met. More detail refer to the link above.
Upvotes: 0
Reputation: 15518
You can use the log parser plugin
EDIT: Excerpt from the plugin's documentation
Job Configuration Go to menu: Jenkins -> job name -> Configure Go to section : Post-build Actions Check the "Console output (build log) parsing" checkbox. "Mark build Unstable on Warning" option: check to have parsed warnings mark the build 'unstable'. "Mark build Failed on Error" option : check to have parsed errors mark the build 'failed'. "Select Parsing Rules" : select the set of rules to use for parsing the logs of this job's builds (Notice that this list is derived from the global configuration )
Upvotes: 1
Reputation: 16305
I use the Log Parser Plugin for cases like this. just configure what you are looking for. In your case it might be as simple as looking for 'Exception'. I used to parse the output of shell scripts, to find sql errors (but still ignoring some that I don't care about).
Upvotes: 1