Sbt ignore tests

For the SonarQube work in Jenkins, we would like to continue, even if some tests may fail. Currently, Sonar Runner did not start because the test fails. In Maven you just add -DtestFailureIgnore = true, but I can't find anything like this for SBT.

I found a onFailurething for sbt, but I have not found any examples of using this anywhere. Can this be used to ignore test crashes, so build work continues and then Sonar Runner starts?

Or is there a setting in Jenkins to ignore the build result? We use the sbt clean coverage testReport command as a build command and have a Sonar Runner after the build.

+4
source share
1 answer

Finally found a solution on my own.

In SBT, you can define a new task A that captures the result of another task B. This dependency ensures that task B starts when a new task A starts. Having captured the result, the result of task B is not the result of task A, so if B fails, A not (should) fail.

So, in this case, I added that I created new ciTests tasks for 'build.sbt'

// Define a special test task which does not fail when any test fails,
// so sequential tasks (like SonarQube analysis) will be performed no matter the test result.
lazy val ciTests = taskKey[Unit]("Run tests for CI")

ciTests := {
  // Capture the test result
 val testResult = (test in Test).result.value
}

Now, in Jenkins’s assignment, he builds a project using SBT using commands (using the SCOTEBE SBT plugin ):

update coverage ciTests coverageReport

This assembly will successfully ignore any failed tests. Therefore, the next build step to launch SonarRunner will begin the analysis of the Scala project and put the results into SonarQube.

@hugo-zwaal , , .

+4

All Articles