检查 Azure DevOps 中的任务状态
Checking status of task in Azure DevOps
我正在尝试编写一个 jenkins 作业来自动检查 Azure DevOps 任务的状态以清理 git 个连接到任务数量的分支(git 在 Azure DevOps 之外)。
为了获取工作项,我找到了一个 api 调用:
GET https://dev.azure.com/{organization}/{project}/_apis/wit/queries/{query}?api-version=5.1
然而,当我使用它(填充了正确的信息)时,我得到了 203 状态代码:
16:52:19 Response Code: HTTP/1.1 203 Non-Authoritative Information
16:52:19 Success code from [100‥399]
[Pipeline] echo
16:52:19 Status: 203
我发现信息表明我需要以某种方式使用个人访问令牌来解决这个问题,所以我创建了一个,但在对 Azure DevOps 的 api 调用中找不到 PAT 使用示例。有人想通了吗?
这取决于您使用的框架:
- curl 和 .net httpclient 示例:Get started with the REST APIs
- .Net 客户端:.NET client libraries for Azure DevOps and TFS
- Powershell:
谢谢 Aleksander,第一个 link 指点我回答。
curl -u {username}[:{personalaccesstoken}] https://dev.azure.com/{organization}/_apis/projects?api-version=2.0
之后,我深入研究了如何在 jenkins 中使用 HTTP 请求插件:
def response = httpRequest authentication:'credentialsID', url:'https://dev.azure.com/{organization}/{project}/_apis/wit/queries/{query}?api-version=5.1'
其中 credentialsID 是包含 PAT 的 jenkins 凭证。这就是我的问题的答案。谢谢。
现在我需要找到一种方法来从响应中提取工作项状态。 ;)
我正在尝试编写一个 jenkins 作业来自动检查 Azure DevOps 任务的状态以清理 git 个连接到任务数量的分支(git 在 Azure DevOps 之外)。
为了获取工作项,我找到了一个 api 调用:
GET https://dev.azure.com/{organization}/{project}/_apis/wit/queries/{query}?api-version=5.1
然而,当我使用它(填充了正确的信息)时,我得到了 203 状态代码:
16:52:19 Response Code: HTTP/1.1 203 Non-Authoritative Information
16:52:19 Success code from [100‥399]
[Pipeline] echo
16:52:19 Status: 203
我发现信息表明我需要以某种方式使用个人访问令牌来解决这个问题,所以我创建了一个,但在对 Azure DevOps 的 api 调用中找不到 PAT 使用示例。有人想通了吗?
这取决于您使用的框架:
- curl 和 .net httpclient 示例:Get started with the REST APIs
- .Net 客户端:.NET client libraries for Azure DevOps and TFS
- Powershell:
谢谢 Aleksander,第一个 link 指点我回答。
curl -u {username}[:{personalaccesstoken}] https://dev.azure.com/{organization}/_apis/projects?api-version=2.0
之后,我深入研究了如何在 jenkins 中使用 HTTP 请求插件:
def response = httpRequest authentication:'credentialsID', url:'https://dev.azure.com/{organization}/{project}/_apis/wit/queries/{query}?api-version=5.1'
其中 credentialsID 是包含 PAT 的 jenkins 凭证。这就是我的问题的答案。谢谢。 现在我需要找到一种方法来从响应中提取工作项状态。 ;)