Skip to content

Instantly share code, notes, and snippets.

@damienpontifex
Last active October 25, 2022 09:35
Show Gist options
  • Save damienpontifex/a5a55dd8556119b807d6f19d2ada1d03 to your computer and use it in GitHub Desktop.
Save damienpontifex/a5a55dd8556119b807d6f19d2ada1d03 to your computer and use it in GitHub Desktop.
Get labels applied to PR. Used if we want to do custom actions in the build based on those labels. We should set them as environment variables or whatever action you want
pool:
vmImage: 'ubuntu-latest'
jobs:
- job: Job1
steps:
- script: |
LABELS_JSON=$(curl -H "Authorization: Bearer ${SYSTEM_ACCESSTOKEN}" "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/git/repositories/$(Build.Repository.Name)/pullRequests/$(System.PullRequest.PullRequestId)/labels?api-version=5.1-preview.1")
echo $LABELS_JSON
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
displayName: Get PR Labels
condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'))
- pwsh: |
$labels = Invoke-RestMethod -Uri "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/git/repositories/$(Build.Repository.Name)/pullRequests/$(System.PullRequest.PullRequestId)/labels?api-version=5.1-preview.1" `
-Authentication Bearer `
-Token (ConvertTo-SecureString -String $(System.AccessToken) -asPlainText -Force)
$labels.value | ForEach-Object {
echo "##vso[task.setvariable variable=$($_.name);isOutput=true]true"
echo $_.name
}
displayName: Get PR Labels pwsh
name: PrLabels
condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'))
- job: Job2
dependsOn: Job1
condition: eq(dependencies.Job1.outputs['PrLabels.DeployPR'], 'true')
steps:
- script: Activated Deployment script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment