如何使用 Rest API 在 TFS 中检索构建的单元测试结果?
构建定义使用 VNext(Visual Studio 2015 更新 3)。
var vssConnection = new VssConnection(_configurationSpec.TeamProjectCollection,
new VssClientCredentials());
_buildClient = vssConnection.GetClient<BuildHttpClient>();
Run Code Online (Sandbox Code Playgroud) 似乎我无法再通过 API https://docs.microsoft.com/en-us/rest/api/vsts/release/definitions/update?view=vsts-rest-5.0更新 VSRM 版本定义
唯一我改变的事情是从版本号11来12获取释放定义之后。
API 网址:https://.vsrm.visualstudio.com/One/_apis/Release/definitions?api-version=5.0-preview.3
响应:{ "$id": "1", "innerException": null, "message": "您正在使用版本定义的旧副本。刷新您的副本并重试。", "typeName": "Microsoft.VisualStudio .Services.ReleaseManagement.Data.Exceptions.InvalidRequestException, Microsoft.VisualStudio.Services.ReleaseManagement2.Data", "typeKey": "InvalidRequestException", "errorCode": 0, "eventId": 3000 }
我尝试了api 版本4.1和5.0预览 api 版本。同样的错误。我将 PostMan 与 PAT 一起使用。GET 工作正常。
你能告诉我我做错了什么吗?
azure-devops azure-pipelines-release-pipeline azure-devops-rest-api
我正在使用 Azure DevOps 的官方 Python REST API: https: //github.com/Microsoft/azure-devops-python-api
感谢这些示例,我已经能够从 ids 检索有关测试用例的信息。
如何从查询(WIQL)中做到这一点?
这是到目前为止我的代码(带有修改后的令牌和链接):
from vsts.vss_connection import VssConnection
from msrest.authentication import BasicAuthentication
token = "hcykwckuhe6vbnigsjs7r3ai2jefsdlkfjslkfj5mxizbtfu6k53j4ia"
team_instance = "https://tfstest.toto.com:8443/tfs/Development/"
credentials = BasicAuthentication("", token)
connection = VssConnection(base_url=team_instance, creds=credentials)
def print_work_items(work_items):
for work_item in work_items:
print(
"{0} {1}: {2}".format(
work_item.fields["System.WorkItemType"],
work_item.id,
work_item.fields["System.Title"],
)
)
WIT_CLIENT = (
"vsts.work_item_tracking.v4_1.work_item_tracking_client.WorkItemTrackingClient"
)
wit_client = connection.get_client(WIT_CLIENT)
def get_TC_by_id(desired_ids):
work_items = wit_client.get_work_items(ids=desired_ids, error_policy="omit")
print_work_items(work_items)
def get_TC_from_query(query):
# THIS FUNCTION IS NOT WORKING...
work_items = wit_client.get_work_items(query=query, error_policy="omit")
print_work_items(work_items)
get_TC_by_id([1035375]) …Run Code Online (Sandbox Code Playgroud) 我希望通过 Azure 的 REST API 获取当前期间给定资源(不是整个订阅或资源组)在 MS Azure 上花费的实时当前金额(例如:本月到目前为止,我们已经花费了 X$此资源)。我已经研究了 Billing API 和一般 REST API 文档(以及他们的 node.js SDK),但我找不到任何似乎可以做到这一点的东西。
有没有人做过类似的事情?任何帮助将不胜感激。
尝试从其他项目复制发布模板时出现以下错误
“VS402982:未为‘PROJECT-ENV’阶段设置保留策略。不推荐使用发布管道级别的保留策略。
{
"id": 8,
"name": "PROJECT-ENV",
"rank": 1,
"owner": "@{displayName=Zoe MacKay; _links=; id=; uniqueName=Zoe.MacKay;imageUrl=https://dev.azure.com/incrementalgroup/_apis/GraphProfile/MemberAvatars/}",
"variables": "",
"variableGroups": "",
"preDeployApprovals": "@{approvals=System.Object[]; approvalOptions=}",
"deployStep": "@{id=27}",
"postDeployApprovals": "@{approvals=System.Object[]; approvalOptions=}",
"deployPhases": "",
"environmentOptions": "@{emailNotificationType=OnlyOnFailure; emailRecipients=release.environment.owner;release.creator; skipArtifactsDownload=False; timeoutInMinutes=0; enableAccessToken=False; publishDeploymentStatus=True; badgeEnabled=False; autoLinkWorkItems=False; pullRequestDeploymentEnabled=False}",
"demands": "",
"conditions": "",
"executionPolicy": "@{concurrencyCount=1; queueDepthCount=0}",
"schedules": "",
"currentRelease": "@{id=70; url=https://vsrm.dev.azure.com/; _links=}",
"retentionPolicy": "@{daysToKeep=30; releasesToKeep=3; retainBuild=True}",
"processParameters": "",
"properties": "",
"preDeploymentGates": "@{id=0; gatesOptions=; gates=System.Object[]}",
"postDeploymentGates": "@{id=0; approvals:[]; gatesOptions=; gates=System.Object[]}",
"environmentTriggers": ""
},
Run Code Online (Sandbox Code Playgroud)
从当前版本复制。
在 Azure DevOps 中,我创建了一个 Build。在那个构建中,我创建了一个 ProjectBuildNumber Pipeline 变量,该变量在排队时可设置。然后在选项 -> 内部版本号格式下使用该变量来设置我在 Azure 中显示的内部版本号。
但是,我试图在我正在构建/部署的代码中设置该 ProjectBuildNumber 变量。有没有办法可以在我的 Build 中有一个 Task 来更新该 ProjectBuildNumber 并更新 Azure DevOps 中的 Build 号?
根据 MS文档,为了向 Azure DevOps 发送 json 请求,我们应该使用以下代码:
{“op”:“add”,“path”:“/fields/System.WorkItemType”,“value”:“任务”},{“op”:“add”,“path”:“/fields/System.WorkItemType”。状态”,“值”:“待办事项”}
我的问题是如何使用 C# 中的这段代码?
我已从 Azure Devops 用户界面生成了个人访问令牌,但无法使用它向 Devops API 发出请求。
我尝试了许多不同的标头字段,但我总是被重定向到登录页面,就好像我没有经过身份验证一样。
token = #Token generated on Devops project page
token_bytes = token.encode('utf-8')
token64 = base64.b64encode(token_bytes)
authorization_string = "basic " + str(token64)
repo_endpoint_url = "https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=5.1".format(organization=organization, project=project)
headers = {"Content-Type" : "application/json", "Authorization" : authorization_string}
response = requests.get(repo_endpoint_url, headers)
Run Code Online (Sandbox Code Playgroud)
响应始终为 203,登录页面为 HTML。如果标头中没有访问令牌,这就是我期望看到的内容。
我尝试过使用“Bearer”而不是“basic”,我尝试过添加 {username}:{token} 以及许多其他小调整。
我究竟做错了什么?
python request access-token azure-devops azure-devops-rest-api
我在 Azure Devops 上有一个管道,我正在尝试使用 REST api 以编程方式/无头方式运行:https ://docs.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run% 20pipeline?view=azure-devops-rest-6.0
到目前为止一切顺利,我可以进行身份验证并开始运行。我想将数据传递到这个管道,文档建议可以variables在请求正文中使用。我的请求正文:
{
"variables": {
"HELLO_WORLD": {
"isSecret": false,
"value": "HelloWorldValue"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的管道 YAML 如下所示:
trigger: none
pr: none
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Bash@3
inputs:
targetType: 'inline'
script: |
KEY=$(HELLO_WORLD)
echo "Hello world key: " $KEY
Run Code Online (Sandbox Code Playgroud)
然而,这给了我一个错误“HELLO_WORLD:找不到命令”。
我尝试向管道添加“HELLO_WORLD”变量并启用“让用户在运行此管道时覆盖此值”设置。这导致HELLO_WORLD变量不再是未知的,而是它停留在其初始值上,并且在我使用 REST api 触发运行时未设置
如何使用 REST api 将变量传递给管道?仅为特定的运行/构建设置变量值很重要
我找到了另一个 API 来运行构建,但似乎您不能使用个人访问令牌身份验证,就像您可以使用管道 api - 仅 OAuth2 - https://docs.microsoft.com/en-us/rest/ api/azure/devops/build/builds/queue?view=azure-devops-rest-6.0
azure-devops azure-devops-extensions azure-devops-rest-api azure-devops-pipelines
我在使用控制台应用程序验证 Azure Devops API 时遇到问题
在 AzureDevOps 上调用 Get Projects API 后,我得到一个重定向...到登录页面
curl -u :${B64_PAT} "https://dev.azure.com/xxxxxxxxxxxx/_apis/projects?api-version=6.0"
Run Code Online (Sandbox Code Playgroud)
返回:
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="https://spsprodsbr1.vssps.visualstudio.com/_signin?rea
Run Code Online (Sandbox Code Playgroud)
我需要从“Java 服务器应用程序”调用此 API,但返回登录页面时遇到问题。但我想遵循设备身份验证流程
我试图列出与工作项关联的所有拉取请求,但根据工作项 API,似乎没有办法获取它:
GET https://dev.azure.com/{org}/{project}/_apis/build/builds/123456/workitems?api-version=6.0
Run Code Online (Sandbox Code Playgroud)
上面返回工作项列表,例如:
{
"count": 40,
"value": [
{
"id": "156267",
"url": "https://dev.azure.com/xxx/_apis/wit/workItems/12345"
},
...
]
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我仍然决定查询每个返回的工作项,我仍然看不到拉取请求。例如:
GET https://dev.azure.com/xxx/_apis/wit/workItems/12345
Run Code Online (Sandbox Code Playgroud)
上面返回一个关于对工作项进行的更新的 JSON 对象,但这可以是提交、状态更新或注释。
有没有办法获取每个工作项目的 PR 列表?
谢谢
azure-api-management azure-api-apps azure-devops azure-devops-rest-api
azure-devops ×9
azure ×2
c# ×2
python ×2
rest ×2
tfs ×2
access-token ×1
azure-pipelines-release-pipeline ×1
devops ×1
request ×1