Copying build artifacts

I’m currently trying to move our Gradle (Android) build into a GitLab CI.

GitLab CI works in pipelines, where the pipeline consists of stages, and stages consist of jobs. The first stage in my case is called “build”, and it, well, builds. I call gradle assembleRelease in this stage. If this stage succeeds, the build moves to the next stage in the pipeline. Stages are isolated from each other by fresh docker containers. However, build results can be defined as artifacts, and in this case, I defined the app/build folder as a build artifact, as it contains all the compiled .class files.

The second stage in the pipeline now copies this folder back into a fresh checkout of the project, and runs gradle testReleaseUnitTest. I would expect gradle to notice that the project has already been built, and use the existing .class files, and only compile and run the tests. However, for some reason, gradle thinks my build files are out of date, and runs the whole build again, and then runs the tests. For smaller projects, this doesn’t take too long, but for our larger projects, this takes a significant amount of time that it shouldn’t take.

Anyone have hints as to why this is happening?

Gradle maintains a bunch of state in the project’s .gradle directory.

The way we do this in our Jenkins pipelines is by re-using the original “workspace” in its entirety, no additional checkouts. For us, this is the safest thing to do since we do not need to worry about what directories or files a build uses (ie; a build that puts some output files outside the build directory).

Thank you, I didn’t know that folder contained vital build information. Simply telling the GitLab CI to also float that folder between the build stages did the trick! It’d be a shame to move everything into a single stage in the CI pipeline, because having multiple stages offers some nice insights. It seems to work nicely when copying the .gradle folder around, so I’m going to configure all the pipelines to do that.