Force tests to be run if they exist

(Steve Cohen) #1

I’m looking for a way to say, globally, that if a java-based project has tests, the jar or war task that builds them depends on the test task running.

Our organization does not do much JUnit-type testing but it does a little. We have other methods of testing that we do more of. I just found that a test was failing but the project’s jenkins build was never running the test.

There are various ways I could force this to happen on a buiild-script-by-build-script basis, but I am looking for a way that would avoid changing hundreds of build scripts.

One possibility would be to rely on the jenkins templates I use. I could simply add “test” to the list of tasks that each jenkins job runs. However, a minority of these jobs have no java content whatsoever, and therefore no “test” task. I suppose I could add a default test task in such circumstances that does nothing.

Are there any other ideas out there?

(Steve Cohen) #2

What worked was to apply the java plugin everywhere, whether needed or not, which gives a test task that can then be invoked by a Jenkins template. This gives us essentially a no-op test task in every project, which becomes operational with the inclusion of tests.

Since most of our projects use the same plugin, it was fairly painless to do this.

(Chris Doré) #3

Instead of applying the java plugin in order to get a test task, could you wire up your custom test tasks to Gradle’s check lifecycle task, which in turn is depended on by build?

(Steve Cohen) #4

I am not familiar with “wiring up” these tasks and don’t use “build”, defaultTasks or any of that, instead supplying the necessary tasks on the command line, which is easy enough to do with jenkins - especially jenkins templates, since most of our projects follow the same basic pattern.

Not saying my way is right, you may be proposing a reasonable and likely better alternative, but this system has evolved the way it has, and changing will be a big deal. But thanks for pointing out another idea.

(Chris Doré) #5

Sorry, I should have been more direct than “wiring up”. All I meant was something along the lines of tasks.check.dependsOn( <your test task(s)> ). The check task is one of the lifecycle tasks added by the ‘base’ plugin.