ð Hello, team!
I've been tasked with decreasing the time taken to run our build pipelines and decided on using gradle caching via:
variables:
GRADLE_USER_HOME: $(Pipeline.Workspace)/.gradle
steps:
- task: Cache@2
inputs:
key: 'gradle | "$(Agent.OS)" | **/build.gradle.kts' # Swap build.gradle.kts for build.gradle when using Groovy
restoreKeys: |
gradle | "$(Agent.OS)"
gradle
path: $(GRADLE_USER_HOME)
displayName: Configure gradle caching
- task: Gradle@2
inputs:
gradleWrapperFile: 'gradlew'
tasks: 'build'
options: '--build-cache'
displayName: Build
- script: |
# stop the Gradle daemon to ensure no files are left open (impacting the save cache operation later)
./gradlew --stop
displayName: Gradlew stop
The first run built the cache as expected and then the second build utilised the cache for 4 of the 7 build tasks, however, any subsequent builds then ran all of the tasks again from scratch.
After a week of scratching my head and scouring Google my ADO build history had disappeared so I couldn't see the successful and unsuccessful runs. I pushed a dummy commit to instigate the building of the cache, I then pushed a 2nd dummy commit to utilise the cache (which again worked), however, the 3rd dummy commit actually utilised the cache and so did a 4th. Nothing had changed in the code so I don't understand why it suddenly started working?
Because of the time elapsed and the setup of our repos, I deleted my initial branch and created it again from an up-to-date version of master. I then repeated the process and now none of my builds are utilising cache ðĪŠ
The builds that did use cache have the same cache hit on the same artifact ID/key as the ones that didn't use the cache. Is the gradle caching always inconsistent in your experience?
I will post the details of the successful and unsuccessful ADO pipeline runs in a second.