简体   繁体   中英

Jenkins build fails when closing Spring ApplicationContext

Why does running failing tests within a Spring application context cause my Jenkins build to crash?

I am using Ant to build my application and run JUnit tests on Jenkins.

I have not experienced any problems while running my Ant build within Eclipse, with or without failing tests.

However, when I try to run the build with Jenkins, the build fails without recording an exception when it has finished running the JUnit tests:

...
[junit] INFO: Executing Stored Procedure with parameters {@pivoting=1, @ignoreReference=0}
[junit] Tests run: 7, Failures: 1, Errors: 0, Time elapsed: 7.831 sec
[junit] Sep 22, 2015 4:23:57 PM org.springframework.context.support.AbstractApplicationContext doClose
[junit] INFO: Closing org.springframework.context.support.GenericApplicationContext@8a590d1: 
    startup date [Tue Sep 22 16:23:52 BST 2015]; root of context hierarchy

BUILD FAILED
E:\Jenkins\jobs\workspace\AntBuilds\build.xml:336: Tests failed

Total time: 16 seconds
Build step 'Invoke Ant' marked build as failure
Archiving artifacts
Recording test results
Finished: FAILURE

The output above is unexpected, as I have configured the build to be simply UNSTABLE if tests fail, and I have configured a JaCoCo report to be published after the tests have been run.

Usually I would see something more like:

 [junit] INFO: Closing org.springframework.context.support.GenericApplicationContext@6a38e598: display name [org.springframework.context.support.GenericApplicationContext@6a38e598]; startup date [Tue Sep 22 16:01:10 BST 2015]; root of context hierarchy
    [junit] Tests FAILED
[jacoco:report] Loading execution data file E:\Jenkins\jobs\jacoco.exec
[jacoco:report] Writing bundle 'Coverage Report' with 117 classes
...etc

Removing the failing tests allows the build to continue as normal:

BUILD SUCCESSFUL
Total time: 36 seconds
Archiving artifacts
Recording test results
[JaCoCo plugin] Collecting JaCoCo coverage data...
[JaCoCo plugin] **/**.exec;**/dist/WEB-INF/classes;**/src; locations are configured
[JaCoCo plugin] Number of found exec files for pattern **/**.exec: 1
[JaCoCo plugin] Saving matched execfiles:  E:\Jenkins\jobs\myJob\jacoco.exec
... etc

My answer so far

I have been successfully building other applications on Jenkins. The difference is that these tests are marked with a Spring application context:

@ContextConfiguration(locations="file:WEB-INF/MyJob-servlet.xml")
@RunWith(SpringJUnit4ClassRunner.class)

I have been wondering if Jenkins fails to close the Application Context when tests fail, as this line appears for the failed build just before the 'BUILD FAILED' message:

Closing org.springframework.context.support.GenericApplicationContext@8a590d1: 
  startup date [Tue Sep 22 16:23:52 BST 2015]; root of context hierarchy

I have needed to upgrade to:

  • JUnit-4.4
  • spring-integration-test-2.1.3.RELEASE

Is this hunch correct? If so, is this a bug with Jenkins / Spring / incompatible versions, or is my implementation incorrect?

If a test fails then Jenkins fails the build by default. The stability of the build is calculated by how much builds have been failing recently. So if failing tests didn't cause your build to fail, then test would have no influence on stability, and then you can't do stuff like email people that the build failed and what commit caused it, and what test failed, which is highly useful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM