0

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...

Stav Alfi
  • 13,139
  • 23
  • 99
  • 171

1 Answers1

1

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
          }
Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
  • thanks! i will try it. (on other topic, this is extrimly complicated and i don't understand why no ci makes it easy and gives us a working solution out of the box. this is needed in every pipeline for every programming language in every product and company) – Stav Alfi Aug 17 '20 at 10:19