How to get Github Labels from Pull Request - Azure Pipelines

524 Views Asked by At

I am trying to read Github labels from Pull Requests as I want to run certain Azure pipeline tasks only if a label bug is present on the Pull Request.

Currently, I have as follows:

steps:
  - bash: |
      if curl -s -H 'Authorization: <pat-token>' "https://api.github.com/repos/$BUILD_REPOSITORY_ID/issues/$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER/labels" | grep '"name": "bug"'
      then 
        echo '##vso[task.setvariable variable=hasLabel;isOutput=true]true"
      else
        echo "Label Bug not found"
      fi
      echo "Value of LabelFlag is : ${hasLabel}" 
    displayName: check for label on PR
    name: checkPRLabel    

I am getting Label Bug not found even if the label actually exists - indicating there may be something wrong in the way I am trying to read the labels from Pull Request. When I try to run the curl alone - I get the Not found as an output of that API call. Any suggestions on how else to read the labels from Pull Request?

0

There are 0 best solutions below