Create Azure Devops environment from script - azure

I would like to create an Azure DevOps Pipeline Environment from Powershell.
Using Azure CLI or the Azure REST API however, I can not find any information on this.
There are some notions about the environments in the release but that's not what I need.
When using the portal following URL is called "/_apis/distributedtask/environments" but can't find any information about this REST API endpoint.
Does anyone know how to automate this?

You're right, If I check the network section when I create a new environment I can see it uses this api:
https://dev.azure.com/{org}/{project}/_apis/distributedtask/environments
With this JSON body:
{
"description":"",
"name":"test"
}
I don't see it domunetd but it should work :)

Related

How to test Azure Data factory linked service using API

I am trying to create and use Azure data factory by Rest API but while creation of linked service connection has created successfully but when I checked connection it got failed so is there anything to do test connection by API or PowerShell command.
There is no this method in Microsoft documentation.You can track this feature here.
But there is a blog about testing link service by PowerShell.Here is the script on github.
Hope this can help you.
Now, you can use one of cmdlet in azure.datafactory.tools PowerShell module:
Test connection of Linked Service (preview)
# Example 1
$LinkedServiceName = 'AzureSqlDatabase1'
Test-AdfLinkedService #params -LinkedServiceName $LinkedServiceName
Alternatively, if you prefer, you can run such test as part of your CI/CD process in Azure DevOps installing #adftools extension, which uses the same PS module behind the scenes.
More: https://sqlplayer.net/adftools
Disclaimer: I'm author of the tool.

Azure DevOps API: get all testcase steps

Is there a way to get all the testcase steps data via Azure DevOps API?
I was able to find the solution:
GET https://{host}/{collection}/{project}/_apis/testplan/Plans/{plan id}/Suites/{suite id}/TestCase/{testcase id}
You need to use this particular Endpoing,
POST https://dev.azure.com/{organization}/{project}/_apis/test/Runs/{runId}/results?api-version=5.0
and access TestActionResultModel
The Azure DevOps api has endpoints for returning test runs, results and cases. The api is wrapped in a PowerShell module called AzurePipelinesPS that has functions like
Get-APTestSuiteList
Get-APTestRunList
Get-APTestRun
Get-APTestRunStatistic
Get-APTestResultList
Get-APTestResult
Get-APTestPlanList
The following command will return a list of all your test cases in a suite.
Get-APTestSuiteList -Session 'youSessionName'
Be sure to setup a session locally with New-APSession when first installing the module. You can find the session documentation here.

Azure Devops custom extension and current release context

With Azure Devops Services, I need to get azure devops user id which triggered a release, from task.json.
I've got a datasourcebinding with Azure API Management service. This has to get Azure API Management tag based on user id. I've tried different approach :
{
"target": "TEST",
"endpointId": "$(ConnectedServiceName)",
"endpointUrl": "{{endpoint.url}}/subscriptions/{{endpoint.subscriptionId}}/resourceGroups/$(ResourceGroupName)/providers/Microsoft.ApiManagement/service/$(APIM)/products?tags=**$(Release.RequestedForId)**&api-version=2019-12-01",
"resultSelector": "jsonpath:$.value[*]",
"resultTemplate": "{\"Value\" : \"{{{id}}}\", \"DisplayValue\" : \"{{{properties.displayName}}}\" }"
},
I tried also with {{Release.RequestedForId}} but it didn't work.
I saw different resources for datasourcebinding support :
tfs:teamfoundation – Any micro service hosted within TFS (e.g. Build, Test etc.)
tfs:packaging – Packaging service
tfs:feed – Feed service
tfs:rm – Release Management service
tfs:governance - Governance service
tfs:ems - Extension Management service
I found examples for tfs:feed and tfs:teamfoundation only.
Is there any section for users ? Is there any additional information apart from Azure Devops Services REST API ?
Quite few examples in but none for user request.
Is it possible to get current context release variables or azure devops user id directly in task.json ?
This would be a huge help.
Thank you !
You made a small misatke. Instead of Release.RequestedForId please give a try for Release.Deployment.RequestedFor of Release.Deployment.RequestedForId
Docs for Release.Deployment.RequestedFor says:
The display name of the identity that triggered (started) the
deployment currently in progress. Not available in TFS 2015.
Example: Mateo Escobedo
Docs for Release.Deployment.RequestedForId says:
The ID of the identity that triggered (started) the deployment
currently in progress. Not available in TFS 2015.
Example: 2f435d07-769f-4e46-849d-10d1ab9ba6ab
You have this written here.

How to create Azure DevOps Product Backlog Item using Apache NiFi

I am developing a component using Apache NiFi which should have functionality to create Azure DevOps work item in case of any failures. In NiFi side I will be using NiFi InvokeHTTP processor which supports HTTP request methods.
I am trying to find out Azure DevOps rest API and sample HTTP request that can be used to create a task/work item using a rest call method. I am going through Azure DevOps documentations but not getting any sample rest call service that can be used to create task/bug/work item and looking for assistance to build the rest URL to create task/Product Work Items in VSTS.
You can check this doc which describe how to create work item with rest api in Azure Devops.
The format of url is:
POST https://dev.azure.com/{org name}/{project name}/_apis/wit/workitems/${type}?api-version=5.1-preview.3
Note: DO NOT lost $ before {type}, such as if you want to add task, please refer this sample: /_apis/wit/workitems/$task?api-version=5.1-preview.3
For request body:
[
{
"op": "add",
"path": "/fields/System.Title",
"value": "workitem created"
}
]

Visual Studio Team Services: Raw link to build artifacts

I see several examples of Azure Resource Manager templates, referencing artifacts directly in Git Hub.
As in the following example, taken from this quick start template:
"modulesUrl": {
"type": "string",
"defaultValue": "https://github.com/Azure/azure-quickstart-templates/raw/master/dsc-extension-azure-automation-pullserver/UpdateLCMforAAPull.zip",
"metadata": {
"description": "URL for the DSC configuration package. NOTE: Can be a Github url(raw) to the zip file (this is the default value)"
}
As an orgnaisation, we can't use free Git Hub as code is public and as we pay for VSTS already... At the moment, we have to upload artifacts to Azure Storage Accounts using the VSTS build task Azure Resource Group Deployment task and reference them from there. It would be nice if we could remove this step.
So, is there a way to reference artifacts directly from a VSTS repository in a similar way to Git Hub? I assume the URI would require some form of authentication, such as a PAT token.
All I can find is this, but I think it is referring to packages. I don't need to create packages for ARM templates and DSC configurations.
There is a task called Azure Resource Group Deployment Task, we use this to deploy the ARM template.
According to you sample template, it's using publicly accessible http/https URLs in GitHub. Afraid this is not accessible via vsts url. In VSTS you need to follow below process (Need to use a SAS Token):
You could provide some extra parameters using the output variables defined in the Azure File Copy Task (storageURI, storageToken). This are needed because in the template we use the _artifactsLocation and _artifactsLocationSasToken parameters to build the storage URL to the files.
More details please refer this blog: Setting up VSTS with ARM Templates

Resources