Is it possible to get the code coverage as part a build step?

Hello!

I am trying to get the code coverage via the REST API and this works if I test it manually but obviously it fails as part of a build step because the code coverage is set AFTER the build is finished. Is there any way to call my curl POST request after the code coverage is done?

Is it possible to post code coverage as a build step? I am trying to post the code coverage and the build status to gitlab. The status works as when I run it as the last build step it seems to get SUCCESS as value and I am able to post that to gitlab. I am still wondering how this is possible, as I would expect the value to be only successful AFTER the build has run.

Is it possible to trigger a command only when a build has failed? Is the SUCCESS value I request via REST really correct? It does not make sense to me to get SUCCESS as long as the buid is running, but it seems to work

0
2 comments

Hi,

With the current setup it's not possible, as coverage reports are read after the full build process (all build steps) is completed. Code coverage is usually collected in report files that might be able to be collected by a custom build runner.

Builds are considered successful as long as they haven't failed, thus you can get SUCCESS for an ongoing build before it fails. Once a failure condition is met, it will be turned to FAILURE, even while it's running. As some build steps and dependencies can be configured to run even after a failure, that can lead to a running build with the "FAILURE" state.

To understand why gitlab status is posted properly as a last build step, we'd first need to know how you are doing it. If you have it as a build feature, then it's done afterwards, not as a build step. If you do it in a different manner, then that's controlling the status that is being posted.

Triggering commands when a build has failed is not particularly easy, but not impossible. You can set up a new build with a snapshot dependency, create a script that checks for the status of the previous build and in case of failure runs your command. That way the new command will always be run but as soon as it detects success it's discarded.

0

I solved it by adding a new build configuration and set the VCS to not checkout. This configuration has a single step: Code Coverage. This configuration gets a snapshot dependency. It gets a trigger "Build finished" on this dependency configuration.

There I use the REST API to get both success state and coverage as the other build will be finished and post it via REST API to gitlab. Because it is a dependency i can access both the build number, the branch name and the revision number - all the things I need.

0

Please sign in to leave a comment.