Open atbagga opened 5 years ago
Command | Description |
---|---|
az pipelines environment create | Create an environment |
az pipelines environment list | Show all environments in a project |
az pipelines environment show | Show details of an environment |
az pipelines environment delete | Delete an environment |
az pipelines environment resource add | Add a resource to an environment |
az pipelines environment resource list | List all the resources in an environment |
az pipelines environment resource delete | Delete a resource in an environment |
Any ETA for this? It would be very useful for us to be able to read environment metadata (even if it was just in the form of hashtags in the description) and use that to influence the terraforming that's happening in our branch yaml pipeline.
Environments concept is still undergoing changes due to which they haven't made the APIs public yet. Until the APIs for environments are released we cannot support these commands or comment on an ETA for it.
Can't you release an preview just like with AKS preview features that were associated by an Azure-Cli preview?
@BoSoeborgPetersen Preview features still require the API to be exposed publically even if it is released in preview mode. So we will have to wait for the API release before we can introduce these commands.
If you still need to automate something related.. you can checkout the API being called from the UI and use CLI az devops invoke
command to send the same request from CLI.
@atbagga Okay, fair enough, thanks for the info.
I am not using Azure DevOps Server, so how would you suggest that I "checkout the API being called from the UI"?
@BoSoeborgPetersen Networks tab in the browser developer tools windows. e.g. here is a screenshot from chrome..
@atbagga Thank you very much.
I figured out that to perform CRUD operations on environments using 'az devops invoke' either:
az devops invoke --area distributedtask --resource environments --route-parameters project=<project> [enviromentId=<id>] --http-method <CRUD> --api-version 6.0-preview -o json --in-file <config_file_path>.json
or:
az devops invoke --area environments --resource environments --route-parameters project=<project> [enviromentId=<id>] --http-method <CRUD> --api-version 6.0-preview -o json --in-file <config_file_path>.json
can be used, as specified by the templates returned from 'az devops invoke':
{
"area": "distributedtask",
"id": "8572b1fc-2482-47fa-8f74-7e3ed53ee54b",
"maxVersion": 6.0,
"minVersion": 5.0,
"releasedVersion": "0.0",
"resourceName": "environments",
"resourceVersion": 1,
"routeTemplate": "{project}/_apis/{area}/{resource}/{environmentId}"
}
or:
{
"area": "environments",
"id": "d86b72de-d240-4d6f-8d06-08c2d66b015d",
"maxVersion": 6.0,
"minVersion": 5.2,
"releasedVersion": "0.0",
"resourceName": "environments",
"resourceVersion": 1,
"routeTemplate": "{project}/_apis/pipelines/{resource}/{environmentId}"
}
Also to add Kubernetes resources to environments using 'az devops invoke' either:
az devops invoke --area distributedtask--resource kubernetes --route-parameters project=<project> environmentId=<environment_id> [resourceId=<id>] --http-method POST --api-version 6.0-preview --in-file <config_file_path> -o json
or:
az devops invoke --area environments --resource kubernetes --route-parameters project=<project> environmentId=<environment_id> [resourceId=<id>] --http-method POST --api-version 6.0-preview --in-file <config_file_path> -o json
can be used, as specified by the templates returned from 'az devops invoke':
{
"area": "distributedtask",
"id": "73fba52f-15ab-42b3-a538-ce67a9223a04",
"maxVersion": 6.0,
"minVersion": 5.0,
"releasedVersion": "0.0",
"resourceName": "kubernetes",
"resourceVersion": 1,
"routeTemplate": "{project}/_apis/{area}/environments/{environmentId}/providers/{resource}/{resourceId}"
}
or:
{
"area": "environments",
"id": "73fba52f-33ab-42b3-a538-ce67a9223b15",
"maxVersion": 6.0,
"minVersion": 5.2,
"releasedVersion": "0.0",
"resourceName": "kubernetes",
"resourceVersion": 2,
"routeTemplate": "{project}/_apis/pipelines/environments/{environmentId}/providers/{resource}/{resourceId}"
}
I can also delete Kubernetes resources using --http-method DELETE
, with resourceId=<id>
.
The only problem now is that I cannot figure out how to get a list of resources for an environment, so that I can use the ID's of the resources to delete and replace them with new ones?
I tried:
az devops invoke --area environments --resource kubernetes --route-parameters project=<project> environmentId=<environment_id> --http-method GET --api-version 6.0-preview -o json
but it is not supported without an resource ID:
request failed: The requested resource does not support http method 'GET'.
I cannot find any relevant templates that seem to cover this either with 'DistributedTask' or 'Environment', as the area.
Also:
az devops invoke --area environments --resource environments --route-parameters project=<project> --http-method GET --api-version 6.0-preview
does not return the resources associated with the environment?
Would be useful if this could also include the ability to manipulate and list tags associated with pipeline environments as well.
I am currently using a number of VMs in an environment and use tags to target specific deployments to the correct machines (think 3 tier app sort of arrangement), I would like to be able to get a list of VMs that match a certain tag so that I can then use the Agent Name as a variable for other pipelines.
I would truly appreciate this as well.
Any update on this? This feature would be really helpful. Surely the environment API is set by now.
i'm able to get the list of kubernetes resources with curl, same should work with az rest i guess:
curl -u:<PAT> "https://<ORGANIZATION>/<PROJECT>/_apis/distributedtask/environments/<ENVIRONMENT_ID>?expands=resourceReferences&api-version=6.0-preview.1"
Any ETA for this? specifically the add/delete VMresources to a environments.
Related https://github.com/MicrosoftDocs/azure-devops-docs/issues/11921 @tl24. Until then our best bet is to utilize the REST API As mentioned above with the documentation starting here: https://learn.microsoft.com/en-us/rest/api/azure/devops/distributedtask/environments?view=azure-devops-rest-6.0.
A bit of a bummer because of the need to manage the PAT ourselves instead of allowing the Azure CLI to handle it...
Apologizes for double posting; but I have been digging on this more, our need was to understand who had access to Approve in the checks, this led me to this StackOverflow Post: https://stackoverflow.com/questions/61471634/add-remove-pipeline-checks-using-rest-api
The original comments seemed to indicate that this was not possible, however after a bit more digging I found @JtMotoX 's Repository which gave a semi decent work around. I have reproduced the contents of that StackOverflow Post here:
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