我希望能够获取 PR 消息并将其作为变量存储在 Azure Devops 中,以便我可以更改标题以** SKIP TEST **
在管道中扫描该标题,而不是手动通过变量 UI。
我想我只需要执行某种 REST API 调用,因为我已经有了 PR ID 和其他识别信息。然后使用读取输出并将值存储到变量的工具。
在 YAML 管道(而不是经典)上执行此操作
steps:
- bash: |
PR_TITLE="$(curl --silent -u azdo:$SYSTEM_ACCESSTOKEN \
$(System.CollectionUri)_apis/git/repositories/$(Build.Repository.ID)/pullRequests/$(System.PullRequest.PullRequestId)?api-version=5.1 \
| jq -r .title)"
echo "##vso[task.setvariable variable=Pr.Title]$PR_TITLE"
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
displayName: Extract pull request title
condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'))
- bash: |
echo "running test"
displayName: Run test
condition: and(succeeded(), not(startsWith(variables['Pr.Title'], '**SKIPTEST**')))
这是一个示例,所有内容都在一行中,但我更喜欢上面的示例,因为新手更容易阅读
steps:
- bash: |
echo "##vso[task.setvariable variable=Pr.Title]"$(curl --silent -u azdo:$SYSTEM_ACCESSTOKEN $(System.CollectionUri)_apis/git/repositories/$(Build.Repository.ID)/pullRequests/$(System.PullRequest.PullRequestId)?api-version=5.1 | jq -r .title)
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
displayName: Extract pull request title
condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'))
- bash: |
echo "running test"
displayName: Run test
condition: and(succeeded(), not(startsWith(variables['Pr.Title'], '**SKIPTEST**')))
此外,如果您更喜欢“标签”而不是更改标题(我自己更喜欢标题,因为它在任何地方都清晰可见)可以使用以下脚本提取标签
steps:
- bash: |
LABELS=$(curl --silent -u azdo:$SYSTEM_ACCESSTOKEN $(System.CollectionUri)_apis/git/repositories/$(Build.Repository.ID)/pullRequests/$(System.PullRequest.PullRequestId)/labels?api-version=5.1-preview.1 | jq .value[].name)
echo "##vso[task.setvariable variable=Pr.Labels]$LABELS"
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
displayName: Get Pull Request Labels
condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'))
- bash: |
echo "running test"
displayName: Run test
condition: and(succeeded(), not(contains(variables['Pr.Labels'], '"skip-test"')))
注意我没有-r
在 JQ 上使用,所以引用了这些值。这允许对字符串进行更明确的检查,而不是匹配可能包含文本作为子字符串的标签。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句