I have posted in the past about the issues a misconfigured cache can have in Azure DevOps Pipelines, or GitHub Actions. Well it caught me out again today, wasting a few hours of my time.
Today, I had a failing integration test in a CI/CD pipeline, but all the tests passed locally. The failing test was looking for a certain number of rows returned from a API with known seed test data. I had revised the seed data and my test, but in my CI/CD pipeline my test was failing as it was still looking for the old number of rows.
Even though I went as far as inspecting the IL code in my test DLL, using dotPeek, to confirm the number of rows expected was the old incorrect value and not the new, it took me far too long to consider that my problem could be a misconfigured cache (again).
My issue was that the folder that the cache was checking was no longer being created due to changes in the pipeline unrelated to my tests. So the cache task could not find it’s target folder, so fell back to caching everything in the working directory. In effect reverting any changes made in the pipeline to the last successful run.
The fix, in this case, was to remove the cache as it was no longer required. However, the real moral of the story is to always consider any caching if your build artifacts are not being updated as you expect.