azureazure-devopsazure-pipelinesazure-cliazure-security

How to update azure pipeline permissions for resource using CLI


so for updating azure pipeline permission for resource, I already found that we can achieve that through using api calls like https://learn.microsoft.com/en-us/rest/api/azure/devops/approvalsandchecks/pipeline-permissions/update-pipeline-permisions-for-resource?view=azure-devops-rest-7.1&tabs=HTTP

the question will be can we use cli to achieve the same outcome?

for cli permission manage I only found https://learn.microsoft.com/en-us/azure/devops/organizations/security/manage-tokens-namespaces?view=azure-devops#update-permissions but it only does something like You can assign allow or deny permissions to a specified user or group, not exactly what I am looking for

so wondering if there are ways to use cli only to achieve the patch operation above

big thanks


Solution

  • There is not specific option for this in Azure CLI. But it that case you can always use az devops invoke

    [Here] is a quite good blog post about this but in general your call should be something like this

    # Write the JSON body to disk
    'Json content' | Out-File -FilePath .\body.json
     
    # PATCH the build with a cancelling status
    az devops invoke `
         --area pipelinePermissions `
         --resource pipelinePermissions `
         --organization https://dev.azure.com/myorgname `
         --route-parameters `
              project="MyProject" `
              resource="ResourceName" `
              resourceType="someType"  `
              resourceId="SomeId" `
         --in-file .\body.json `
         --http-method patch
    

    based on this entry

      {
        "area": "pipelinePermissions",
        "id": "b5b9a4a4-e6cd-4096-853c-ab7d8b0c4eb2",
        "maxVersion": 7.2,
        "minVersion": 5.1,
        "releasedVersion": "0.0",
        "resourceName": "pipelinePermissions",
        "resourceVersion": 1,
        "routeTemplate": "{project}/_apis/pipelines/{resource}/{resourceType}/{resourceId}"
      },