user6604221
user6604221

Reputation:

Jenkins Maven release fails due to log files from unit tests

I unfortunately may have two questions in one, or rather the solution may go two different ways. I have log4j loggers set up in a few classes that I unit test on. When I run mvn clean install it obviously runs those tests and in turn creates a log file (that is usually empty as nothing exciting is being logged). This isn't necessarily a problem except that Jenkins doesn't seem to like this when I do Perform Maven Release. It yells about the workspace having local changes and it cites the log file before declaring failure.

I know its the unit tests because if I changed them to integration tests or ignore them, everything works fine. But I'd like a solution not a workaround.

Are there configurations in Jenkins that can allow me to remedy this?

Or is there a strategy for mocking or ignoring logging for Unit tests?

I don't necessarily want to ignore them, but it is interfering with creating a release.

Upvotes: 1

Views: 166

Answers (2)

Greg Chabala
Greg Chabala

Reputation: 1137

Amit has some good ideas, and I'll suggest a few more:

  • Use slf4j for logging in your project, and don't bind a logging implementation during the test phase
  • going one better, bind slf4j-test during the test phase, which logs to memory. Then you can also write tests against your logging to ensure it happens when you expect it to.

Upvotes: 1

Amit
Amit

Reputation: 1006

I am not quite aware of what Perform Maven Release does, but I can suggest a couple of solutions:

  1. Remove the log file from your source code repository (as the log files gets regenerated on every run, I don't think it should reside in your source code repository).
  2. Add the path of the offending log file to a list of files that are ignored by version control (e.g. git uses a file called gitignore - https://git-scm.com/docs/gitignore)

Hope this helps!

Upvotes: 2

Related Questions