Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Pipelines how filter artifacts per stage for "Manual only" triggered Releases

Let's say I have these 3 Stages: Dev, QC, Prod.

My requirements are:

  1. Artifacts only from specific branches(release/*) can be deployed to QC/Prod
  2. Artifacts from all branches can be deployed to Dev

I can achieve what I want using Artifact filters for "After stage" triggered Releases but I need this for "Manual only".

Is there a workaround that will let me control/filter which artifacts are available for deployment for specific stages/environments?

enter image description here

Basically, I need the Azure DevOps equivalent of Octopus Channels.

Update
I think I'm close to a solution.
In the "Pre-deployment conditions", I can add a new Deployment Gate which makes a Rest API call. e.g URL suffix=/Release/releases/76

Now, I just need to correctly parse the ApiResponse because the below Success criteria doesn't work

eq(root['artifacts[0].definitionReference.branch.id'], 'refs/heads/master')

Evaluation of expression 'eq(root['artifacts[0].definitionReference.branch.id'], 'refs/heads/master')' failed.

like image 425
George Vovos Avatar asked Oct 29 '25 13:10

George Vovos


1 Answers

As you said, you can do this using Deployment gates on your stages.

  1. Create a new Generic service connection from Project Settings -> Pipelines -> Service Connections.
    For service URL something like https://vsrm.dev.azure.com/{OrgName}/{ProjectName}/_apis

  2. On your stage, open the Pre-Deployment Conditions

  3. Enable the Gates option.

  4. Add a new Invoke REST API gate and set the Delay before evaluation to 0 minutes.
    4.1 Set the connection type to Generic.
    4.2 Select the service connection you created in step 1.
    4.3 Set the method to GET.
    4.4 Set the URL suffix to /Release/releases/$(Release.ReleaseId)
    4.5 On the Advanced area, set the Completion Event to ApiResponse.
    4.6 On the Advanced area, set the success criteria to (or startsWith)
    eq(root['artifacts'][0]['definitionReference']['branch']['id'],'refs/heads/master')

Now, if you try to deploy an artifact not from the master branch, the deployment will fail

like image 171
Nick Vovos Avatar answered Nov 01 '25 13:11

Nick Vovos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!