Parallel pipeline builds causing git collisions

Viewed 55

I have a build pipeline set up in Azure devops that runs every time a PR goes into the main branch.

The steps are as follows:

checkout main
install dependencies
npm version to increment
Build
Publish to npm feed
Deploy to a test/staging environment
Push the change to the version number back to git.

Since the build runs every time a PR is completed, occasionally there are parallel builds. Depending on which one finishes first, the push will fail because it is "dirty".

I'm having issues finding a way to bypass it.

Possible methods:

  1. Just suppress the fail when the git push command fails (not ideal).
  2. Force the git push (not ideal).
  3. If a build is queued while one is running, wait until it is complete before starting the new build
  4. Cancel the older build and batch?
  5. Restructure the build process in some way.

Am I missing any?

1 Answers

I'm not sure if this answers you question as you didn't share your pipeline definition (so please do this if you could) but maybe Batching CI runs helps you

If you have many team members uploading changes often, you may want to reduce the number of runs you start. If you set batch to true, when a pipeline is running, the system waits until the run is completed, then starts another run with all changes that have not yet been built.

In this way you will not get concurrent builds, so it seems that can be solution for you if grouped build is acceptable for you.

Related