我有一个函数,该函数调用api以返回相应的构建选项。请注意:
C:\> $build = get-builds sharptop vNext_test_VL -Count 1 -Verbose -BuildStatus completed
VERBOSE: GET
http://tdc1tfsapp01.dayforce.com:8080/tfs/DefaultCollection/sharptop/_apis/build/definitions?name=vNext_test_VL&api-version=5.0 with
0-byte payload
VERBOSE: received 2245-byte response of content type application/json; charset=utf-8; api-version=5.0
VERBOSE: GET
http://tdc1tfsapp01.dayforce.com:8080/tfs/DefaultCollection/sharptop/_apis/build/builds?api-version=5.0&queryOrder=finishTimeDescendin
g&statusFilter=completed&maxBuildsPerDefinition=1&definitions=5963 with 0-byte payload
VERBOSE: received 5287-byte response of content type application/json; charset=utf-8; api-version=5.0
C:\> $build | ft buildNumber,result,parameters
buildNumber result parameters
----------- ------ ----------
58.0.0.29010 succeeded
C:\>
(我用冗长的文字显示了请求)
那么,我们如何得到它们?
编辑1
在Powershell命令行上运行:
C:\> $url = "http://tdc1tfsapp01.dayforce.com:8080/tfs/DefaultCollection/sharptop/_apis/build/builds?api-version=5.0&queryOrder=finishTimeDescending&statusFilter=completed&maxBuildsPerDefinition=1&definitions=5963"
C:\> $b = Invoke-RestMethod $url -UseDefaultCredentials
C:\> $b
count value
----- -----
1 {@{_links=; properties=; tags=System.Object[]; validationResults=System.Object[]; plans=System.Object[]; triggerInfo=; id=602252; buil...
C:\> $b.value|ft buildNumber,result,parameters
buildNumber result parameters
----------- ------ ----------
58.0.0.29011 succeeded
C:\>
编辑2
我们使用本地Azure DevOps 2019。
编辑3
完整的答复是:
{
"_links": {
"self": {
"href": "http://tdc1tfsapp01.xyz.com:8080/tfs/DefaultCollection/ecff38d6-a219-4739-8b97-5e5d8d00e7ed/_apis/build/Builds/602252"
},
"web": {
"href": "http://tdc1tfsapp01:8080/tfs/DefaultCollection/ecff38d6-a219-4739-8b97-5e5d8d00e7ed/_build/results?buildId=602252"
},
"sourceVersionDisplayUri": {
"href": "http://tdc1tfsapp01.xyz.com:8080/tfs/DefaultCollection/ecff38d6-a219-4739-8b97-5e5d8d00e7ed/_apis/build/builds/602252/sources"
},
"timeline": {
"href": "http://tdc1tfsapp01.xyz.com:8080/tfs/DefaultCollection/ecff38d6-a219-4739-8b97-5e5d8d00e7ed/_apis/build/builds/602252/Timeline"
},
"badge": {
"href": "http://tdc1tfsapp01.xyz.com:8080/tfs/DefaultCollection/ecff38d6-a219-4739-8b97-5e5d8d00e7ed/_apis/build/status/5963"
}
},
"properties": {
},
"tags": [
],
"validationResults": [
],
"plans": [
{
"planId": "93fdbc13-a822-4237-beab-504bdae399a3"
}
],
"triggerInfo": {
},
"id": 602252,
"buildNumber": "58.0.0.29011",
"status": "completed",
"result": "succeeded",
"queueTime": "2019-10-17T15:42:14.6046801Z",
"startTime": "2019-10-17T15:42:16.042188Z",
"finishTime": "2019-10-17T17:02:25.934717Z",
"url": "http://tdc1tfsapp01.xyz.com:8080/tfs/DefaultCollection/ecff38d6-a219-4739-8b97-5e5d8d00e7ed/_apis/build/Builds/602252",
"definition": {
"drafts": [
],
"id": 5963,
"name": "vNext_test_VL",
"url": "http://tdc1tfsapp01.xyz.com:8080/tfs/DefaultCollection/ecff38d6-a219-4739-8b97-5e5d8d00e7ed/_apis/build/Definitions/5963?revision=4",
"uri": "vstfs:///Build/Definition/5963",
"path": "\\devOps",
"type": "build",
"queueStatus": "enabled",
"revision": 4,
"project": {
"id": "ecff38d6-a219-4739-8b97-5e5d8d00e7ed",
"name": "SharpTop",
"description": "html cannot search",
"url": "http://tdc1tfsapp01.xyz.com:8080/tfs/DefaultCollection/_apis/projects/ecff38d6-a219-4739-8b97-5e5d8d00e7ed",
"state": "wellFormed",
"revision": 32574427,
"visibility": "private"
}
},
"project": {
"id": "ecff38d6-a219-4739-8b97-5e5d8d00e7ed",
"name": "SharpTop",
"description": "html cannot search",
"url": "http://tdc1tfsapp01.xyz.com:8080/tfs/DefaultCollection/_apis/projects/ecff38d6-a219-4739-8b97-5e5d8d00e7ed",
"state": "wellFormed",
"revision": 32574427,
"visibility": "private"
},
"uri": "vstfs:///Build/Build/602252",
"sourceBranch": "refs/heads/arch/NugetPackageConsolidation",
"sourceVersion": "866fc3b5cecf7648537af0d91172c5c445859cb8",
"queue": {
"id": 3264,
"name": "TDC5DFC1BLD20-CI-feature",
"pool": {
"id": 131,
"name": "TDC5DFC1BLD20-CI-feature"
}
},
"priority": "normal",
"reason": "batchedCI",
"requestedFor": {
"displayName": "Doe, John",
"url": "http://tdc1tfsapp01.xyz.com:8080/tfs/DefaultCollection/_apis/Identities/91f94f95-d229-4e55-bfa3-7e33ff1132af",
"_links": {
"avatar": "@{href=http://tdc1tfsapp01.xyz.com:8080/tfs/DefaultCollection/_apis/GraphProfile/MemberAvatars/win.Uy0xLTUtMjEtNDg3MjU1NDc3LTE2MzE1MjcwMjItMzUxNzQ0NDQyLTEzMzY0}"
},
"id": "91f94f95-d229-4e55-bfa3-7e33ff1132af",
"uniqueName": "xyz\\P123958",
"imageUrl": "http://tdc1tfsapp01.xyz.com:8080/tfs/DefaultCollection/_api/_common/identityImage?id=91f94f95-d229-4e55-bfa3-7e33ff1132af",
"descriptor": "win.Uy0xLTUtMjEtNDg3MjU1NDc3LTE2MzE1MjcwMjItMzUxNzQ0NDQyLTEzMzY0"
},
"requestedBy": {
"displayName": "Microsoft.TeamFoundation.System",
"url": "http://tdc1tfsapp01.xyz.com:8080/tfs/DefaultCollection/_apis/Identities/000007f5-0000-8888-8000-000000000000",
"_links": {
"avatar": "@{href=http://tdc1tfsapp01.xyz.com:8080/tfs/DefaultCollection/_apis/GraphProfile/MemberAvatars/s2s.MDAwMDA3RjUtMDAwMC04ODg4LTgwMDAtMDAwMDAwMDAwMDAwQDAwMDAwMDAwLTAwMDAtMDAwMC0wMDAwLTAwMDAwMDAwMDAwMA}"
},
"id": "000007f5-0000-8888-8000-000000000000",
"uniqueName": "000007F5-0000-8888-8000-000000000000@00000000-0000-0000-0000-000000000000",
"imageUrl": "http://tdc1tfsapp01.xyz.com:8080/tfs/DefaultCollection/_api/_common/identityImage?id=000007f5-0000-8888-8000-000000000000",
"descriptor": "s2s.MDAwMDA3RjUtMDAwMC04ODg4LTgwMDAtMDAwMDAwMDAwMDAwQDAwMDAwMDAwLTAwMDAtMDAwMC0wMDAwLTAwMDAwMDAwMDAwMA"
},
"lastChangedDate": "2019-10-17T17:02:26.297Z",
"lastChangedBy": {
"displayName": "Microsoft.TeamFoundation.System",
"url": "http://tdc1tfsapp01.xyz.com:8080/tfs/DefaultCollection/_apis/Identities/000007f5-0000-8888-8000-000000000000",
"_links": {
"avatar": "@{href=http://tdc1tfsapp01.xyz.com:8080/tfs/DefaultCollection/_apis/GraphProfile/MemberAvatars/s2s.MDAwMDA3RjUtMDAwMC04ODg4LTgwMDAtMDAwMDAwMDAwMDAwQDAwMDAwMDAwLTAwMDAtMDAwMC0wMDAwLTAwMDAwMDAwMDAwMA}"
},
"id": "000007f5-0000-8888-8000-000000000000",
"uniqueName": "000007F5-0000-8888-8000-000000000000@00000000-0000-0000-0000-000000000000",
"imageUrl": "http://tdc1tfsapp01.xyz.com:8080/tfs/DefaultCollection/_api/_common/identityImage?id=000007f5-0000-8888-8000-000000000000",
"descriptor": "s2s.MDAwMDA3RjUtMDAwMC04ODg4LTgwMDAtMDAwMDAwMDAwMDAwQDAwMDAwMDAwLTAwMDAtMDAwMC0wMDAwLTAwMDAwMDAwMDAwMA"
},
"orchestrationPlan": {
"planId": "93fdbc13-a822-4237-beab-504bdae399a3"
},
"logs": {
"id": 0,
"type": "Container",
"url": "http://tdc1tfsapp01.xyz.com:8080/tfs/DefaultCollection/ecff38d6-a219-4739-8b97-5e5d8d00e7ed/_apis/build/builds/602252/logs"
},
"repository": {
"id": "ed3ba028-9f6d-44a0-9274-a9c7dcdae79c",
"type": "TfsGit",
"name": "xyz",
"url": "http://tdc1tfsapp01.xyz.com:8080/tfs/DefaultCollection/SharpTop/_git/xyz",
"clean": null,
"checkoutSubmodules": false
},
"keepForever": false,
"retainedByRelease": false,
"triggeredByBuild": null
}
答案 0 :(得分:1)
问题可能是,尽管buildNumber
和result
都是简单的字符串,但是parameters
是一个具有多个值的对象,并且您的脚本在绘制时无法处理该值?
例如,这是我通过邮递员对其中一个版本调用类似请求时得到的:
"buildNumber": "20191017.1",
"result": "failed",
"parameters": "{\"BuildConfiguration\":\"release\",\"BuildPlatform\":\"any cpu\",\"system.debug\":\"false\"}",
修改
好的,似乎parameters
并未发送给通过持续集成触发的构建。
特定版本的parameters
属性分别仅包含用户设置的参数(因此可以在队列时间设置的参数)。对于自动触发的构建,队列时间将不会设置任何内容,因此将被跳过。
如果未指定任何内容,它将采用构建定义中定义的变量的值-您可以通过获取定义并检查variables
来访问它:
http://tdc1tfsapp01.dayforce.com:8080/tfs/DefaultCollection/sharptop/_apis/build/definitions/5963
在响应中,您应该找到定义如下的变量:
"variables": {
"system.debug": {
"value": "false",
"allowOverride": true
},
"BuildConfiguration": {
"value": "debug",
"allowOverride": true
},
"BuildPlatform": {
"value": "any cpu",
"allowOverride": true
},
...
}
因此,您的脚本需要设置2个请求,一个用于构建本身,一个用于定义,然后您可以编译用于构建的参数列表。
我还测试了如果您通过REST API对构建进行排队并通过此请求传递一些参数会发生什么,它们确实会以parameters
的形式显示在构建中,就像您在队列时手动设置它们一样。