MrCyber
MrCyber

Reputation: 11

Azure DevOps Cancel deployment of stage when deploying another stage

We currently have our Azure DevOps release setup in the following way:

Release Setup

What I'm trying to accomplish is to cancel the 2:00 PM deployment if the 9:00 AM deployment triggers, as well as cancel the 9:00 AM deployment if the 2:00 PM deployment triggers since we don't really want to deploy the same code twice, or even deploy the previous day's code the following day.

Does anyone know if a way to do this in Azure DevOps?

I've done a lot of searching for extensions, etc. to see if I can find anything, but so far have not been successful. Any help would be greatly appreciated.

Upvotes: 1

Views: 2454

Answers (2)

Shamrai Aleksander
Shamrai Aleksander

Reputation: 15988

Additionally, you may try to use Release Gates with Rest Api or Azure Functions. You can find example here: Azure DevOps release gates with Azure Functions, PowerShell and VS Code

Upvotes: 1

mj1313
mj1313

Reputation: 8459

Assuming you trigger the release at 9:00 AM. Then you can take the following steps to implement it:

1.Add a variable named flag and set it as true in the Variable Tab

enter image description here

2.Add a PowerShell Task to your Test Stage, Starting 9:00 AM Stage and Starting 2:00 PM Stage

(1) Add a powershell task at the end of your Test Stage to set the flag to true.

(2) Add a powershell task on the top of Starting 9:00 AM Stage to check if the variable flag is true, If flag is false then fail this task, Below script is for example.

$flag = “$(flag)”

if(-Not $flag)

{

exit 1

}

Add a powershell task at the end of Starting 9:00 AM Stage to set the flag to false, if this stage is deployed successfully.

Repeat above steps for 2:00 PM Stage.

Upvotes: 0

Related Questions