Perform Some Action if Azure Release Pre-deployment Approval is Rejected - azure

I have a release pipeline defined in Azure DevOps. Pre-deployment approval has been configured in order for the release to be completed.
If approval is rejected, I want to perform some action, maybe run a Python script.
How can I achieve this, within the pipeline itself or otherwise?

You may consider using Service Hooks (Integrate with service hooks, Create a service hook subscription programmatically):

Related

Automatically approving the pipelines which are waiting for manual approval in Azure DevOps(Azure DevOps REST API)

I am using Azure DevOps to implement CI/CD for one of the project.
I have implemented manual approval in the production deployment job/pipelines.
There were 22 pipelines so interested in approving all the pipelines.
I made progress on this ..the below script(Powershell) display the pipelines and builds information.
But I am unable to achieve the end goal.

Calling AZ pipeline API from within pipeline

I would like to call an Azure Pipeline API from within a stage of a Pipeline. Specifically to get the status of one pipeline from another so that a job can be forced to wait until the other pipeline is not busy.
I can call the API with a PAT locally. I am just not sure of the best way of passing auth from within the pipeline. Does the agent have some kind of built in auth mechanism with devops apis? Does the agent itself need a PAT and if so what's the best way of providing it one?
The System.AccessToken as detailed here https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml was whart I required to call pipeline apis.

How to get Azure DevOps pipeline manual cancellation call back

I am using Azure DevOps pipeline to run some jobs. This pipeline has been created using YML.
As I am calling to Azure data factory pipeline using my DevOps pipeline, so if a user manually cancell DevOps pipeline, in that case my Azure Data Factory still in running mode which should ideally not happened.
Is there a way to stop my azure data factory pipeline autmatically whenever there is cancellation of Azure DevOps pipeline from UI?
As a workaround, We could add task power shell task and set the custom condition canceled(), this task will only run if you cancel the build.
Then add power shell script to call the API to cancel the Azure Data Factory pipeline.
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/pipelineruns/{runId}/cancel?api-version=2018-06-01
Also, we could do this via webhook, you could also check this blog and update the json.

Does azure pipelines allow custom action like AWS codepipeline?

Does azure pipelines allow custom action like AWS codepipeline?
I want to create a job worker that will poll azure pipeline for job requests for this custom action, execute the job, and return the status result to azure pipeline.
Something similar to - https://docs.aws.amazon.com/codepipeline/latest/userguide/actions-create-custom-action.html
Tasks are the building blocks for defining automation in a build or release pipeline in Azure DevOps. There are many built-in tasks to enable fundamental build and deployment scenarios. If the existing tasks don't satisfy your needs, you can always build a custom task. Check Task types & usage for more details.
In addition, Visual Studio Marketplace offers a number of extensions; each of which, when installed to your subscription or collection, extends the task catalog with one or more tasks. Furthermore, you can write your own custom extensions to add tasks to Azure Pipelines.
Azure Pipeline Agents
When your pipeline runs, the system begins one or more jobs. An agent is computing infrastructure with installed agent software that runs one job at a time.
You have two options here to choose from: Microsoft-hosted agents or Self-hosted agents
An agent that you set up and manage on your own to run jobs is a self-hosted agent. Self-hosted agents give you more control to install dependent software needed for your builds and deployments. Also, machine-level caches and configuration persist from run to run, which can boost speed.
However, before you install a self-hosted agent you might want to see if a Microsoft-hosted agent pool will work for you. In many cases, this is the simplest way to get going.
With Microsoft-hosted agents, maintenance and upgrades are taken care of for you. Each time you run a pipeline, you get a fresh virtual machine. The virtual machine is discarded after one use. Microsoft-hosted agents can run jobs directly on the VM or in a container. Azure Pipelines provides a pre-defined agent pool named Azure Pipelines with Microsoft-hosted agents.
You can try it first and see if it works for your build or deployment. If not, you can use a self-hosted agent. Check this doc for more details.
I will pull the agent queue from my custom job worker and process the job. Is that possible in azure pipelines?
Based on my understanding of code pipeline and Azure devops, I am afraid what you said should be meaningless.
According to the document Create and add a custom action in CodePipeline, we could to know that:
AWS CodePipeline includes a number of actions that help you configure
build, test, and deploy resources for your automated release process.
If your release process includes activities that are not included in
the default actions, such as an internally developed build process or
a test suite, you can create a custom action for that purpose and
include it in your pipeline.
But for Azure devops, we do not need to create a job worker that will poll CodePipeline for job requests for this custom action. That because the whole process of build/release can be customized. We do not need to add a job worker for additional custom actions.
Azure devops provide a lot of templates when we create the pipeline, we could modify the pipeline directly in the pipeline to add/remove or update the task:
Even we can completely start with a blank pipeline and completely customize the entire build/release process.
So, we do not need to create a job worker for the custom action, just modify your pipeline directly.

Azure pipeline runs forever if not using approval timeout

I have recently moved from Classic release to YAML release pipeline. With Classic release I would simply trigger manually the deployment I was interested in (Dev, Integration, UAT or Production).
However with YAML pipeline I use stages and they are triggered automatically after building. To prevent that, I've added Approval guard on the Integration stage as shown below.
However the pipeline was running indefinitely and would never end. So I've set a 5 minute timeout on approval and now the Integration stage is marked as Skipped if nobody approves.
I feel I'm not doing it the right way as it is quite different from classic release.
Is this the correct way to handle release pipeline when using YAML ?
Is this the correct way to handle release pipeline when using YAML ?
Yes, you are on the correct way (At least for now).
Just as you said in the question, Azure devops does not support manually triggered stage(s) in YAML multi-stage pipelines. So, we could not simply trigger manually the deployment stage we are interested in.
There is an On Roadmap user voice about this request:
Manually triggered stage(s) in YAML multi-stage pipelines
You can look forward to it, and I believe it will meet us soon.
So, your workaround is correct for now.

Resources