jenkins the definitive guide

(Jeff_L) #1
dependencies{
testCompile "junit:junit:4.8.2"
}

uploadArchives {
repositories.mavenDeployer {
configuration = configurations.archives
repository(url: "http://build.server/nexus/content/repositories/snapshots") {
authentication(userName: "admin", password: "password")
}
}
}

In Figure 5.52, “Setting up a Gradle build job”, we use the just configured “Gradle-0.9RC2” instance
to run this Gradle build. In this case, we want to run the JUnit tests and upload the build artifacts to our
local Maven repository. Furthermore we configure our job to collect the test results from **/build/
test-results, the default directory for storing test results in Gradle.


5.10.2.2. Incremental builds


While running a Gradle build job with unchanged sources, Gradle runs its builds incremental. If the
output of a Gradle task is still available and the sources haven’t changed since the last build, Gradle
is able to skip the task execution and marks the according task as up-to-date. This incremental build
feature can decrease the duration of a running build job considerably.


If Gradle evaluates the test task as up-to-date even the execution of your unit tests is skipped. This
can cause problems when running your Gradle build with Jenkins. In our sample build job above we
configured a post build action to publish the JUnit reports of our build. If the test task is skipped by
Gradle, the Jenkins job will be marked as failed with the following message:


Test reports were found but none of them are new. Did tests run?

You can easily fix this by invalidating the output and force a re-execution of your tests by adding the
following snippet to your Gradle file:


test {
outputs.upToDateWhen { false }
}
Free download pdf