I have a requirement to dynamically add/remove or enable disable approval and checks at azure DevOps pipeline environment.
Is there a rest api for this?
Is there a rest api for this?
Yes, it has. BUT, as what the #Krysztof said, we haven't provide such api documents to public as of today. This is because what you are looking for is one feature (configure Check and approval from environments ) that only support for YAML pipeline, and until now, we are developing but does not publish the corresponding rest api (for YAML) docs.
But, as work around, you can catch these apis from F12. Just do action from UI, then capture and analyze corresponds api records to found out what you are expecting.
Here I make the summary to you.
The api that used to add/delete approval and check to environment is:
https://dev.azure.com/{org name}/{project name}/_apis/pipelines/checks/configurations
The corresponding api method for add or delete is Post and DELETE.
Firstly, share you the request body samples which for approval and check added.
1) Add approval to this environment:
{
"type": {
"id": "8C6F20A7-A545-4486-9777-F762FAFE0D4D", // The fixed value for Approval
"name": "Approval"
},
"settings": {
"approvers": [
{
"id": "f3c88b9a-b49f-4126-a4fe-3c99ecbf6303" // User Id
}
],
"executionOrder": 1,
"instructions": "",
"blockedApprovers": [],
"minRequiredApprovers": 0,
"requesterCannotBeApprover": false // The pipeline requester allow to approve it.
},
"resource": {
"type": "environment",
"id": "1", // Environment id
"name": "Deployment" //Environment name
},
"timeout": 43200 // Set the available time(30d) of this approval pending. The measure unit is seconds.
}
2) Add task check, Azure function, Invoke rest api task and etc:
{
"type": {
"id": "fe1de3ee-a436-41b4-bb20-f6eb4cb879a7", // Fixed value if you want to add task check
"name": "Task Check" //Fixed value
},
"settings": {
"definitionRef": {
"id": "537fdb7a-a601-4537-aa70-92645a2b5ce4", //task Id
"name": "AzureFunction", //task name
"version": "1.0.10" //task version
},
"displayName": "Invoke Azure Function", //task display name configured
"inputs": {
"method": "POST",
"waitForCompletion": "false",
"function": "csdgsdgsa",
"key": "436467543756" // These are all task inputs
},
"retryInterval": 5, // The re-try time specified.
"linkedVariableGroup": "AzKeyGroup"// The variable group name this task linked with
},
"resource": {
"type": "environment",
"id": "2",
"name": "Development"
},
"timeout": 43200
}
In this request body, you can find the corresponding task id from our public source code. Just check the task.json file of corresponding task.
3) Add template check:
{
"type": {
"id": "4020E66E-B0F3-47E1-BC88-48F3CC59B5F3", // Fixed value for template check added.
"name": "ExtendsCheck" //Fixed value
},
"settings": {
"extendsChecks": [
{
"repositoryType": "git", // github for Github source, bitbucket for Bitbucket source
"repositoryName": "MonnoPro",
"repositoryRef": "refs/heads/master",
"templatePath": "tem.yml"
}
]
},
"resource": {
"type": "environment",
"id": "6",
"name": "development"
}
}
In this body, if the template source is coming from github or bitbucket, the value of repositoryName should like {org name}/{repos name}.
Hope these are helps.
This is an older question but we had a similar need. There does not appear to be a direct API To query this, but this GitHub Project pointed us in the right direction:
# GET ENVIRONMENT CHECKS (stored under .fps.dataProviders.data['ms.vss-pipelinechecks.checks-data-provider'].checkConfigurationDataList)
GET https://dev.azure.com/{{organization}}/{{project}}/_environments/{{environment_id}}/checks?__rt=fps&__ver=2
As mentioned above under .fps.dataProviders.data['ms.vss-pipelinechecks.checks-data-provider'].checkConfigurationDataList the list of who is authorized is provided.
The officially documented APIs can tell you that there are checks in place; for example:
GET https://dev.azure.com/{organization}/{project}/_apis/pipelines/checks/configurations?resourceType=environment&resourceId={id}
Can tell you that you have checks enabled (including an Approval check) but this isn't super useful as it does not give a list of who can Approve.
Note that you can get the list of environments (to get their resource ID) using this documented API:
GET https://dev.azure.com/{organization}/{project}/_apis/distributedtask/environments?api-version=7.1-preview.1
This is not supported at the moment. You can upvote feature request to show your interest here.
Related
I need to create a task in TFS with PowerShell
I used the VSTeam (A PowerShell module for many features in TFS / Azure DevOps). The item is created. I have a template for the description but i don't know how to insert it to -Description that gets a string
Here is an example of the template:
The build is an hyper link and also the tfs item (patch XXXX)
How can I built the string like this? How to create a link for items?
How to set a bold string?
Can I copy a link from TFS?
There is a new build. The build location:
\\XXXXX\global\QA\
The patches that were added:
Patch 1269263: "Title"
Patch 1271540: "Title"
Have you looked into VSTeam? A PowerShell module for many features in TFS / Azure DevOps.
Set-VSTeamAccount -Account http://localtfs:8080/tfs/DefaultCollection -UseWindowsAuthentication
Set-VSTeamDefaultProject Demo
$additionalFields = #{"System.Tags"= "TestTag"; "System.AreaPath" = "Project\\MyPath"}
Add-VSTeamWorkItem -Title "New Work Item" -WorkItemType Task -AdditionalFields $additionalFields
ID Title Status
-- ----- ------
6 New Work Item To Do
The description field in TFS/Azure DevOps contains HTML text. Any formatting can be done using standard HTML constructs. <i> for italic, <b> for bold <a href="https://....."> for links.
To get the links you may need to invoke other REST APIs to get the build details. Most APE results have a links collection with a web link you can use to direct people to the web page for that thing.
Example from a Build/GET API call:
GET https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/builds/2817
{
"_links": {
"self": {
"href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/Builds/2817"
},
"web": {
"href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_build/results?buildId=2817"
},
"sourceVersionDisplayUri": {
"href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/builds/2817/sources"
},
"timeline": {
"href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/builds/2817/Timeline"
},
"badge": {
"href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/status/36"
}
},
...
...
}
In this case self is the link that retrieved this document. web is the equivalent in the WebUI, etc.
You'll find that other elements returned by the API carry a url property. By folliwing that URL, you'll get the _links collection for that object as well:
...
...
"project": {
"id": "a88536a2-a889-45a3-a955-ddf1af8aeba1",
"name": "azure-devops-extensions",
"description": "This projects hosts the pipelines for all my Azure DevOps marketplace extensions.",
"url": "https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1",
"state": "wellFormed",
"revision": 414360082,
"visibility": "public",
"lastUpdateTime": "2019-06-28T09:48:16.943Z"
},
Following:
GET https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1
{
"id": "a88536a2-a889-45a3-a955-ddf1af8aeba1",
"name": "azure-devops-extensions",
"description": "This projects hosts the pipelines for all my Azure DevOps marketplace extensions.",
"url": "https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1",
"state": "wellFormed",
"revision": 414360082,
"_links": {
"self": {
"href": "https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1"
},
"collection": {
"href": "https://dev.azure.com/jessehouwing/_apis/projectCollections/6ac92044-9ce2-40d0-b882-f6b6648dff8b"
},
"web": {
"href": "https://dev.azure.com/jessehouwing/azure-devops-extensions"
}
},
"visibility": "public",
"defaultTeam": {
"id": "7edc4d0a-3d22-44ee-a6cd-96a3dbf0690f",
"name": "azure-devops-extensions Team",
"url": "https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1/teams/7edc4d0a-3d22-44ee-a6cd-96a3dbf0690f"
},
"lastUpdateTime": "2019-06-28T09:48:16.943Z"
}
This way you can collect the links to the appropriate UI pages to direct your users to.
Azure DevOps provides a view of published artifacts after a build has completed, my question is, is there an API endpoint that lists these artifacts?
This API is not officially documented, but you can get it from the developers tools in the Artifacts page.
So, the API url is:
https://dev.azure.com/{org-id}/_apis/Contribution/HierarchyQuery/project/{project-id}
And the body should be:
{
"contributionIds": [
"ms.vss-build-web.run-artifacts-data-provider"
],
"dataProviderContext": {
"properties": {
"artifactId": {artifact-id},
"buildId": {build-id},
"sourcePage": {
"url": "https://dev.azure.com/{org-id}/{project-id}/_build/results?buildId=1210\u0026view=artifacts\u0026pathAsName=false\u0026type=publishedArtifacts",
"routeId": "ms.vss-build-web.ci-results-hub-route",
"routeValues": {
"project": "{project-id}",
"viewname": "build-results",
"controller": "ContributedPage",
"action": "Execute",
"serviceHost": "{host-id} ({username})"
}
}
}
}
}
In the response you will get items section with the file names.
You can in the first to go the build artifacts page, press on F12 and see the values for the {} in the body I provided.
I am new on Azure and trying to create pipeline through rest api with below URL
https://dev.azure.com/my-org/my_project/_apis/pipelines?api-version=6.1-preview.1
When Source Provider is Azure Git Repo then it working perfectly fine with below request body
{
"folder": "\\",
"name": "Test-Pipeline-1",
"configuration": {
"type": "yaml",
"path":"/azure-pipelines.yml",
"repository":{
"id": "1f13f61c-eade-b36bc515bb5e",
"name": "TestAzure123",
"type":"azureReposGit"
}
}
}
But when Source Provider is Bitbucket Cloud then its not working
{
"folder": "\\",
"name": "Bitbucket-Pipeline",
"configuration": {
"type": "yaml",
"path":"/master-pipeline.yaml",
"repository": {
"id": "sid_07/Bitbucket-repository",
"name": "Bitbucket-repository",
"type": "Bitbucket"
}
}
}
I am getting below exception
{
"$id": "1",
"innerException": null,
"message": "This API does not support creating pipelines with repositories of type Unknown.",
"typeName": "Microsoft.Azure.Pipelines.WebApi.UnsupportedRepositoryTypeException, Microsoft.Azure.Pipelines.WebApi",
"typeKey": "UnsupportedRepositoryTypeException",
"errorCode": 0,
"eventId": 3000
}
Is pipeline creation supported through rest api for bitbucket? or am I missing something? Please help
I have already taken reference from similar issue
https://developercommunity.visualstudio.com/content/problem/1101376/create-pipeline-rest-api-does-not-work.html
Azure Devops rest API for create pipeline with source provider bitbucket not working
I am afraid the REST API Pipelines - Create does not support the creation of a pipeline whose source type is bitbucket at this moment.
When I use the request body below, which I used to create a pipeline for the resource type of github:
{
"folder": "\\",
"name": "Test-Pipeline-2",
"configuration": {
"path": "TestDemo.yml",
"repository": {
"fullName": "xxx/leotest",
"connection": {
"id": "e11d299a-0bfd-4a38-a77c-xxxxxxxx"
},
"type": "bitbucket"
},
"type": "yaml"
}
I got the same error as you:
Then I created that pipeline manually, and use the REST API Pipelines - Get to get the detailed info about this pipeline, I got following info:
"configuration": {
"path": "BitbucketRepo.yml",
"repository": null,
"type": "yaml"
},
"url": "https://dev.azure.com/xxx/xxxxx/_apis/pipelines/146?revision=2",
"id": 146,
"revision": 2,
"name": "BitbucketRepo",
"folder": "\\YAML\\Resources"
We could to know the part of repository: is null.
So, the REST API Pipelines - Create does not support create pipeline with source provider bitbucket at this moment.
For this request, you could add it for this feature on our UserVoice site (https://developercommunity.visualstudio.com/content/idea/post.html?space=21 ), which is our main forum for product suggestions. Thank you for helping us build a better Azure DevOps.
So, experimenting with Plesk's REST API (available as of version 17.8) for a project at work, and I'm starting to get a feel for it. I've been trying to experiment with adding a domain, but it's been giving me errors when I have to specify the hosting type.
The request body itself is as follows:
{
"name":"example.com",
"hosting_type":"virtual",
"description":"Description goes here"
}
This gets the following cryptic response:
{
"code": 1014,
"message": "htype\/vrt_hst is specified but there is no hosting\/vrt_hst"
}
Per the documentation provided at /api/v2/swagger.yml, any of the following values should be allowed: virtual, standard_forwarding, frame_forwarding, none
No matter what I put in, however, I get a variant of the response above (htype\/{type} is specified but there is no hosting\/{type}).
At this point I'm kind of stuck; I'm not sure what to check, and any references when I try to look up the error code go to references on Plesk's XML API instead. What's the missing link here needed to get the request to work?
It looks like system user is not specified - hosting_settings. Try to add domain with full json request. Here is example:
{
"name": "example.com",
"description": "My website",
"hosting_type": "virtual",
"hosting_settings": {
"ftp_login": "test_login",
"ftp_password": "test_pwd"
},
"base_domain": {
"id": 7,
"name": "a10-52-41-48.qa.plesk.ru",
"guid": "b623e93d-dc72-4102-b5f0-ded427cf0fb1"
},
"parent_domain": {
"id": 7,
"name": "a10-52-41-48.qa.plesk.ru",
"guid": "b623e93d-dc72-4102-b5f0-ded427cf0fb1"
},
"owner_client": {
"id": 7,
"login": "a10-52-41-48.qa.plesk.ru",
"guid": "b623e93d-dc72-4102-b5f0-ded427cf0fb1",
"external_id": "b623e93d-dc72-4102-b5f0-ded427cf0fb1"
},
"ipv4": [
"212.192.122.46"
],
"ipv6": [
"2002:5bcc:18fd:c:123:123:123:123"
],
"plan": {
"name": "Unlimited"
}
}
Examples for REST API https://app.swaggerhub.com/apis/plesk/api/v2#/Domains/post_domains
For some reason, I keep getting these weird issues.....
In this case, I have a Key and Endpoint URL for the Automation Account stored as Secrets in a KeyVault (I don't know of a away to extract it natively from Automation Account using ARM).
I can extract these values perfectly and they they are published to the Template that runs a PowerShell extension to pull a DSC Configuration.
For example as seen as an Input deploying the Template:
"RegistrationUrl":"https://ase-agentservice-prod-1.azure-automation.net/accounts/e0799801-a8da-8934-b0f3-9a43191dd7e6"
However, I receive the following error (note the Url in the Error with 3 forward slashes)
"code": "VMExtensionProvisioningError",
"message": "VM has reported a failure when processing extension 'dscLcm'.
Error message: "DSC Configuration 'ConfigureLCMforAAPull' completed with error(s). Following are the first few: The attempt to 'get an action' for AgentId 11A5A267-6D00-11E7-B07F-000D3AE0FB1B from server URL https://ase-agentservice-prod-1.azure-automation.net///accounts/e0799801-a8da-8934-b0f3-9a43191dd7e6/Nodes(AgentId='11A5A267-6D00-11E7-B07F-000D3AE0FB1B')/GetDscAction failed with server error 'ResourceNotFound(404)'.
For further details see the server error message below or the DSC debug event log with ID 4339.
ServerErrorMessage:- 'No NodeConfiguration was found for the agent.'\"."
The Endpoint Url is passed as a Secure String. I tried passing it a normal string - Same problem.
The Key and Endpoint are feed into the Template as Parameters:
"dscKeySecret": {
"type": "securestring",
"metadata": {
"description": "Key for PowerShell DSC Configuration."
}
},
"dscUrlSecret": {
"type": "securestring",
"metadata": {
"description": "Url for PowerShell DSC Configuration."
}
},
These values are used to create a parameter to be passed to the next template that runs the VM Extension.
"extn-settings": {
"value": {
"configuration": {
"url": "[concat(variables('urls').dscScripts, '/', 'lcm-aa-pull', '/', 'lcm-aa-pull', '.zip')]",
"script": "[concat('lcm-aa-pull', '.ps1')]",
"function": "ConfigureLCMforAAPull"
},
"configurationArguments": {
"registrationKey": {
"username": "dsckeySecret",
"password": "[parameters('dscKeySecret')]"
},
"registrationUrl": "[parameters('dscUrlSecret')]",
"configurationMode": "ApplyAndMonitor",
"configurationModeFrequencyMins": 15,
"domain": "[variables('names').domain]",
"name": "dscLcm",
"nodeConfigurationName": "[variables('names').config.ad]",
"rebootNodeIfNeeded": true,
"refreshFrequencyMins": 30
},
"protectedSettings": null,
}
}
The next template receives the Parameters and used in the Properties of the VM's Resources section:
"properties": {
"publisher": "Microsoft.Powershell",
"type": "DSC",
"typeHandlerVersion": "2.22",
"autoUpgradeMinorVersion": true,
"settings": {
"configuration": "[parameters('extn-settings').configuration]",
"configurationArguments": "[parameters('extn-settings').configurationArguments]"
},
"protectedSettings": "[parameters('extn-settings').protectedSettings]"
}
So why is the Url being corrupted with the the first '/' being changed to '///'?
I don't why the Endpoint Url has 3 x '/', but that wasn't the issue.... I wish I found the issue before I posted this question...
I found the Node Configuration Name was wrong with a spelling mistake (hang head in shame)
Thanks anyway!