Like me you might be running already some production websites in Azure but executes the CI/CD on demand, while this is already great on its own as you have Continuous Deployment working, what if you want to deploy automatically when approved on a certain schedule? For example you want to schedule it at night when your traffic is low, definitely you do want to wake up at night to allocate 2 minutes of your time to approve and automatically deploy it. Well here is how I configured our release stages so it automatically schedules after an approval happens.
Initially your stage might look like this
Where all your triggers are in one stage
It is triggered by a release then you schedule it, then an approval happens. This happens exactly in that order, which I guess is a pain as you have to wake up at 3:00 AM in the morning for a release. Not good right? I guess that is why you are here as you have the same scenario. Now the question is how do I change that order? Where release first happens, then approval before a scheduled deploy.
Here is how I reconfigured it and its as simple as separating them in stages.
Ok before delving into the solution, here is how the new solution looks like
First you seek approval (1) then the trigger (2) happens before a deployment (3)
If you can see, once the Continuous Deployment is triggered there is a wait until someone approves it
And once the approval is set, then it will automatically go to the next stage.
So here is how its done step by step. The key here is an Agentless job (1) which I figured out just by playing with Azure DevOps
So what you need to do is create two stages
Go to the stages menu, click on add (1) then select New Stage (2)
select an empty job (1)
Select the Agent Job (1) created, press delete and confirm (2)
No go to the ellipsis menu (1), select add an agentless job (2)
Now you have an agentless job (1) that does nothing but this will be the gate before your next stage. From here you can add the approval process
First lets trigger (1) it by “After Release” (2) in your pipeline
Then trigger this stage to continue if approved, choose pre-deployment approvals (1), then choose who do you want it to be approved by (2)
then go to your next stage, trigger (1) it by “after stage” (2) which is your first stage “seek approval” (3) then enable (4) and choose a schedule (5).
Then your task of deploy to Azure App Service goes here. That simple