In Azure DevOps YML pipeline, how to mandate template call? - azure-devops

I have a template to perform some post build(end of the pipeline) checks. This check must happen in a build, after few jobs successfully finished.
I want to ensure, template call must be the last job in main pipeline and no control to author to skip. How to mandate template usage ?
Because this template based checks not applicable to all pipelines with in Azure DevOps organization.
Is it possible to use template as a decorator backend and conditionally inject it into selected pipelines in a organization ?
Does decorator support parametrization ?

Related

Executing a power automate flow from YAML

Quick question - is there a way to use YAML (in an azure pipeline) to trigger an power automate (or a logic app) with parameters ?
I can see the other way around - so from power automate to trigger an pipeline but not the way i need.
Thanks
We trigger Power Automate Flows by using the Azure DevOps Invoke REST API task. This needs to have a Service Connection of Generic type which is only used to specify the Server URL.
To use this, your Pipeline needs to use an Agentless Job which you choose by clicking the ellipsis in the Pipeline and adding an agentless job.

Azure Devops Service Now - how to get CHANGE_REQUEST_NUMBER/CHANGE_CORRELATION_ID for YAML pipeline

Following the MS documentation here: https://learn.microsoft.com/en-us/azure/devops/pipelines/release/approvals/servicenow?view=azure-devops
I've set up an Azure DevOps environment with the Service Now Pre-deployment check and can successfully create a new standard change request in Service Now and update it using the UpdateServiceNowChangeRequest#2 task.
However, I'm struggling to find a way to access the CHANGE_REQUEST_NUMBER and CHANGE_CORRELATION_ID that are available to the UpdateServiceNowChangeRequest#2 tasks
The documentation describes how to get to these using the release pipeline by having a name for the gate and using $(PREDEPLOYGATE.mygatename.CHANGE_REQUEST_NUMBER), but there is no option in the YAML setup to name a gate and I can't seem to find another way to get to these variables
I've tried just enumerating all the environment variables in the pwsh task (i.e. gci env:\ ) but nothing relating to these variables shows up.

Pipelines -> Runs -> Run pipeline howto provide pipeline resource in request body

I have a parent pipeline which publish pipeline artifacts.
And the child pipeline which has a parent pipeline added as a resource pipeline and consumes the parent's artifacts.
I would like to programatically (by REST API) create a run of multistage child pipeline and provide the parent pipeline resource.
How to craft a request body for pipelines' run endpoint?
According to ms docs PipelineResourceParameters contains only version? Are there any examples how to use it?
Is it a resource name and buildnumber?
https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run%20pipeline?view=azure-devops-rest-6.1#pipelineresourceparameters
Where can I find any examples of requests bodies?
The pipeline resource is set in advance in the pipelines. By default, the pipeline will select last successful run as the resource. We can choose the pipeline resource version when we run the pipeline.
Here is my request body sample:
{
"resources":{
"pipelines":{
"Parent":{
"version":"20201225.1"
}
}
}
}
If you want to find the sample of Rest API, in addition to referring to the examples in the official documentation, you can also check the developer tool (F12) in the browser. For example, run a pipeline manually and check the rest api:

In Azure Devops I want my yaml pipeline only to execute after the previous execution of the same pipeline has completed

I tried batch: true setting described here, but it seems to:
ignore commits that are pushed when a pipeline is running. I want the last commit to trigger a pipeline after the current run of that pipeline has finished
be ignored when you publish directly from CI by pressing build
Has someone found a way to configure a pipeline to run as I have described.
You can try adding a Invoke REST API check on the agent pool. The rest api will get the previous build and evaluate its status. So when new build is queued targeting the agent pool. The Invoke REST API will be invoked, this new build will only start when the response of the rest api is evaluated to true.
Please check below steps:
1, create a service connection to your azure devops organization.
Go Project Setting--> Service connections under Pipelines-->Click new service connection--> select Generic to create a generic service connection.
Then Edit the service connection type the information shown in below screenshot. Check here to get a Personal access token.
2, add Invoke REST API check on the agent pool**.
Go Project Setting--> Agent Pools under Pipelines-->Select the agent pool--> Click the 3dots -->Click Approvals and checks.
.
3, Click the "+"--> Choose Invoke REST API
4, Edit the Invokde Rest API
Select the generic service connection to your azure devops created in the first step.
Set the fields as below:
URL suffix and parameters: _apis/build/builds?definitions=the DefinitionId of your pipeline&$top=2&queryOrder=queueTimeDescending&api-version=5.1
Success criteria: eq(root['value'][1]['status'], 'completed')
please check here for more information about build rest api.
Note: Since the Invoke Rest api check is set on agent pool scope. It may have effects on other pipelines that target this agent pool. For example, if the desired yaml pipeline is waiting its previous run to complete. And now another pipeline targeting this same agent pool is triggered, it will have to wait for the previous run of desired yaml pipeline to complete too.

Include pipeline variables in release notifications

I am using Azure Devops (formerly VSTS) releases to deploy a project.
In my release pipeline I have a power shell task that may not succeed in ways that do not indicate a deployment failure. I would like to alert users when these conditions arise.
I have suppressed the errors in the power shell script and am using them to control flow to subsequent pipeline tasks.
Is there a way include pipeline variables in the notifications Azure Devops sends when a deployment is complete?
No, the notification template is not customizable and this feature was requested: Customise VSTS email templates
But you may log your pipeline variables with powershell script: Write-Host "My var: $(my_variable)"
User-defined variables