Last active
October 11, 2022 22:46
-
-
Save Wind010/b5ff4d40774263848c287df98c7fb1b8 to your computer and use it in GitHub Desktop.
Create an Azure DevOps release definition from file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Usage | |
| # ./create_azure_devops_release_definition.sh "YOUR_ORG" "YOUR_PROJECT" | |
| Organization=$1 | |
| Project=$2 | |
| azureDevOpsTokenUri="https://vssps.dev.azure.com/$Organization" | |
| azureDevOpsReleaseUri="https://vsrm.dev.azure.com/$Organization" | |
| username=$(az ad signed-in-user show --query "displayName") | |
| echo "Retrieving Azure DevOps Personal Access Token (PAT) for '$username'" | |
| read authId pat < <( echo $(az rest --method post \ | |
| --uri "$azureDevOpsTokenUri/_apis/Tokens/Pats?api-version=6.1-preview" \ | |
| --headers Content-Type=application/json \ | |
| --resource "https://management.core.windows.net/" \ | |
| --body '{ "displayName": "Release Definition Management", "scope": "vso.release_manage" }' \ | |
| -o tsv \ | |
| --query [patToken.authorizationId,patToken.token] | |
| )) | |
| echo "Creating release definition with $release_definition_json_path" | |
| curl -u $username:$pat -X POST "$azureDevOpsReleaseUri/$Project/_apis/release/definitions?api-version=6.0" \ | |
| -H "Content-Type: application/json" \ | |
| -d @"$release_definition_json_path" | |
| echo "Removing path with authorizationid=$authId" | |
| az rest --method delete \ | |
| --resource "https://management.core.windows.net/" \ | |
| --uri "$azureDevOpsTokenUri/_apis/tokens/pats?authorizationId=$authId&api-version=7.1-preview.1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment