PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, September 27, 2022

[FIXED] How to disable builds-concurrency on master in circle-ci/azure-pipeline/any-other-ci?

 September 27, 2022     azure-pipelines, circleci, continuous-delivery, continuous-deployment, continuous-integration     No comments   

Issue

It is considered a bug to run deployment scripts concurrenctly.

I failed to find a solution to it in circle-ci, azure-pipeline, code-fresh and more..

Bitbucket-pipelines has a very nice solution:

  • only one deployment script is running against a specific enviroment
  • new builds will automatically stop older (running) builds

As I want to move out of bitbucket, I can't do it until I will find any other CI that has this basic ability.


Maybe I'm missing something because to my knowlege, all the CIs themselves must have this problem as well when they deploy their new features. unless they use jenkins and just lock the project haha...


Solution

I think you can achieve this with azure release pipeline.

If you are to use Classic UI Azure release pipeline. You can achieve stopping older builds when new builds is queued by configuring Deployment queue settings. See below screenshot:

1,Set the Maximum number of parallel deployments to control the parallel deployment. Check Deploy latest and cancel others will only deploy the latest queued deployment. All the previous queued(not running yet) deployment will be cancelled. But if a previous deployment is running. The latest queued build will have to wait until the running build to be completed unless you manually cancel it.

enter image description here

If you want to cancel the older running builds you can add a script task to call the rest api to cancel the previous running builds. See the example in below yaml pipeline example:

2, To only deploy to one target you can configure the Deployment targets as below in a deployment group job

enter image description here

If you are to use Yaml pipleline. The Deploy latest and cancel others and Deployment group jobs are not supported for yaml pipeline. See this use voice here.

In Yaml pipeline, you can use deploy jobs and environments instead. You can configure the Define approvals and checks for the Environment to enable the Exclusive lock to ensure only a single run deploys to this environment at a time. And configure the deployment strategy to set the maxparallel deployment.

To cancel the older running builds you can add a script task to call the rest api. See below example: Check my answer to this thread for more information.

- task: PowerShell@2
  inputs:
        targetType: inline
        script: |
          $header = @{ Authorization = "Bearer $(system.accesstoken)" }
          $buildsUrl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds?api-version=5.1"
          echo $buildsUrl
          $builds = Invoke-RestMethod -Uri $buildsUrl -Method Get -Header $header
          $buildsToStop = $builds.value.Where({ ($_.status -eq 'inProgress') -and ($_.definition.name -eq "$(Build.DefinitionName)") -and ($_.id -ne $(Build.BuildId))})
          ForEach($build in $buildsToStop)
          {
            echo $build.id
            $build.status = "cancelling"
            $body = $build | ConvertTo-Json -Depth 10
            $urlToCancel = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds/$($build.id)?api-version=5.1"
            echo $urlToCancel
            Invoke-RestMethod -Uri $urlToCancel -Method Patch -ContentType application/json -Body $body -Header $header
          }


Answered By - Levi Lu-MSFT
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing