I need to fail a build on TFS 2018 if its pipeline is not fully complete. Batching just the build is not enough; the linked release must be finished as well before another build can begin. My idea is to do this in a PowerShell script via the REST API.
I see in the official documentation here that there's a property called TaskStatus. It provides a value of inProgress, presumably for releases that are in progress. This might do the trick, but there's no indication of how to actually use it.
Using the REST API, how can I get the TaskStatus of a given release?
The in process and some other values such as succeeded, canceled just stand for the status of a task in release pipeline.
You could simply use the Rest API to get a release
GET https://fabrikam.vsrm.visualstudio.com/MyFirstProject/_apis/release/releases/{releaseId}?api-version=4.1-preview.6
There should be a value called status:
"id": 18,
"name": "Release-18",
"status": "abandoned",
"createdOn": "2017-06-16T01:36:20.397Z",
"modifiedOn": "2017-06-16T01:36:21.07Z",
"modifiedBy": {
"id": "4adb1680-0eac-6149-b5ee-fc8b4f6ca227",
"displayName": "Chuck Reinhart",
"uniqueName": "fabfiber#outlook.com",
"url": "https://app.vssps.visualstudio.com/A168224e4-29ff-4081-9954-c8780ce81117/_apis/Identities/4adb1680-0eac-6149-b5ee-fc8b4f6ca227",
"imageUrl": "https://fabfiber-inc.visualstudio.com/_api/_common/identityImage?id=4adb1680-0eac-6149-b5ee-fc8b4f6ca227"
},
"createdBy": {
"id": "4adb1680-0eac-6149-b5ee-fc8b4f6ca227",
"displayName": "Chuck Reinhart",
"uniqueName": "fabfiber#outlook.com",
"url": "https://app.vssps.visualstudio.com/A168224e4-29ff-4081-9954-c8780ce81117/_apis/Identities/4adb1680-0eac-6149-b5ee-fc8b4f6ca227",
"imageUrl": "https://fabfiber-inc.visualstudio.com/_api/_common/identityImage?id=4adb1680-0eac-6149-b5ee-fc8b4f6ca227"
},
"environments": [
{
"id": 69,
"releaseId": 18,
"name": "Dev",
"status": "notStarted",
"variables": {},
"preDeployApprovals": [],
"postDeployApprovals": [],
"preApprovalsSnapshot": {
"approvals": [
{
"rank": 1,
"isAutomated": false,
"isNotificationOn": false,
"approver": {
"id": "4adb1680-0eac-6149-b5ee-fc8b4f6ca227",
"displayName": "Chuck Reinhart",
"uniqueName": "fabfiber#outlook.com",
"url": "https://app.vssps.visualstudio.com/A168224e4-29ff-4081-9954-c8780ce81117/_apis/Identities/4adb1680-0eac-6149-b5ee-fc8b4f6ca227",
"imageUrl": "https://fabfiber-inc.visualstudio.com/_api/_common/identityImage?id=4adb1680-0eac-6149-b5ee-fc8b4f6ca227"
},
"id": 0
}
You could fetch the value status in your return json file, and judge if the release succeed or failed. Finally according to this status to trigger another build or not.
Update
A sample of the returned json with task's status info:
"deploymentJobs": [
{
"job": {
"id": 5,
"timelineRecordId": "855ea6d6-9ed0-442d-b921-0c4add8bb068",
"name": "Release",
"dateStarted": "2018-07-04T08:53:05.9133333Z",
"dateEnded": "2018-07-04T08:53:21.34Z",
"startTime": "2018-07-04T08:53:05.9133333Z",
"finishTime": "2018-07-04T08:53:21.34Z",
"status": "succeeded",
"rank": 1,
"issues": [],
"agentName": "DFA00"
},
"tasks": [
{
"id": 1,
"timelineRecordId": "fa3bb635-eab4-4c1b-9cc0-fdccd7ced33f",
"name": "Initialize Job",
"dateStarted": "2018-07-04T08:53:06.5833333Z",
"dateEnded": "2018-07-04T08:53:06.8033333Z",
"startTime": "2018-07-04T08:53:06.5833333Z",
"finishTime": "2018-07-04T08:53:06.8033333Z",
"status": "succeeded",
"rank": 1,
"issues": [],
"agentName": "DFA00",
"logUrl": "http://xxxx:8080/tfs/DefaultCollection/7658559e-6e61-422a-952b-a5fce0b6ca1d/_apis/Release/releases/49/environments/49/tasks/1/logs?releaseDeployPhaseId=54"
},
There should be timelinerecord, starttime, finishtime, status for a task deployment result in a single release.
Related
I have the following definition in my pipeline that I am running on Azure DevOps Server Version Dev17.M153.3
After saving the change I can see the following content has been added to pipeline definition
"approvals": [
{
"rank": 1,
"isAutomated": false,
"isNotificationOn": false,
"approver": {
"displayName": "Aouslender, Alexey",
"url": "http://tdc1tfsapp01:8080/tfs/DefaultCollection/_apis/Identities/2d86d86b-fe02-4e22-aa53-4315cdb3821c",
"_links": {
"avatar": {
"href": "http://tdc1tfsapp01:8080/tfs/DefaultCollection/_apis/GraphProfile/MemberAvatars/win.Uy0xLTUtMjEtMzMwNDk4NzQ2Ni0xODkxMDA3NDIzLTI5MjUxNTc3OTctNDU4NDA1"
}
},
"id": "2d86d86b-fe02-4e22-aa53-4315cdb3821c",
"uniqueName": "DOMAIN\\PXXXXXX",
"imageUrl": "http://tdc1tfsapp01:8080/tfs/DefaultCollection/_apis/GraphProfile/MemberAvatars/win.Uy0xLTUtMjEtMzMwNDk4NzQ2Ni0xODkxMDA3NDIzLTI5MjUxNTc3OTctNDU4NDA1",
"descriptor": "win.Uy0xLTUtMjEtMzMwNDk4NzQ2Ni0xODkxMDA3NDIzLTI5MjUxNTc3OTctNDU4NDA1"
},
"id": 3546
}
]
Now I am exporting pipeline, using export option. Then I am deleting pipeline and importing it using exported json file.
The imported pipeline missing the Approvers definition, nevertheless I can see the definition in exported json.
"preDeployApprovals": {
"approvals": [
{
"rank": 1,
"isAutomated": false,
"isNotificationOn": false,
"approver": {
"displayName": "Aouslender, Alexey",
"url": "http://tdc1tfsapp01:8080/tfs/DefaultCollection/_apis/Identities/2d86d86b-fe02-4e22-aa53-4315cdb3821c",
"_links": {
"avatar": {
"href": "http://tdc1tfsapp01:8080/tfs/DefaultCollection/_apis/GraphProfile/MemberAvatars/win.Uy0xLTUtMjEtMzMwNDk4NzQ2Ni0xODkxMDA3NDIzLTI5MjUxNTc3OTctNDU4NDA1"
}
},
"id": "2d86d86b-fe02-4e22-aa53-4315cdb3821c",
"uniqueName": "DOMAIN\\PXXXXXX",
"imageUrl": "http://tdc1tfsapp01:8080/tfs/DefaultCollection/_apis/GraphProfile/MemberAvatars/win.Uy0xLTUtMjEtMzMwNDk4NzQ2Ni0xODkxMDA3NDIzLTI5MjUxNTc3OTctNDU4NDA1",
"descriptor": "win.Uy0xLTUtMjEtMzMwNDk4NzQ2Ni0xODkxMDA3NDIzLTI5MjUxNTc3OTctNDU4NDA1"
},
"id": 3535
}
],
"approvalOptions": {
"requiredApproverCount": null,
"releaseCreatorCanBeApprover": true,
"autoTriggeredAndPreviousEnvironmentApprovedCanBeSkipped": false,
"enforceIdentityRevalidation": false,
"timeoutInMinutes": 0,
"executionOrder": 1
}
}
Am I missing something here or is it actually a Microsoft bug?
It's by design. Following properties in the release definition are not imported: Agent Queues, Deployment Groups, Deployment Group Tags, Approvals, Variable Groups and values of secret variables.
Generally if in the same team project you can Clone the release definition directly.
I try to use the patch request to complete my task and I get a response for task completion, but it doesn't update on the wunderlist app. I did about 9 revision. I get a response that shows completion, but when I return to the app it shows no update. Here my response from the request:
{
"id": 3898040341,
"created_at": "2018-06-01T10:20:00.703Z",
"created_by_id": 24870738,
"created_by_request_id": "worker:w:w:recurring_task_creator:parent-3858561041",
"recurrence_type": "day",
"recurrence_count": 1,
"due_date": "2018-06-02",
"completed": true,
"completed_at": "2018-06-18T12:30:20.547Z",
"completed_by_id": 24870738,
"starred": false,
"list_id": 350926181,
"revision": 9,
"title": "Turn on computer",
"type": "task"
}
It says I completed it today, but the apps didn't update on either my phone, tablet, or completed.
Please help. Thanks.
Nevermind, I figure it out. The id of the task changes everytime it is completed. This is for a recurring task. So I need to update the current request with a new ID.
Old request result with ID 3952832467
{
"id": 3952832467,
"created_at": "2018-06-19T11:42:13.366Z",
"created_by_id": 24870738,
"created_by_request_id": "worker:w:w:recurring_task_creator:parent-3949658004",
"recurrence_type": "day",
"recurrence_count": 1,
"due_date": "2018-06-05",
"completed": true,
"completed_at": "2018-06-19T11:42:55.835Z",
"completed_by_id": 24870738,
"starred": false,
"list_id": 350926181,
"revision": 2,
"title": "Turn on computer",
"type": "task"
}
Same request result, but with no ID 3952834287:
{
"id": 3952834287,
"created_at": "2018-06-19T11:42:56.132Z",
"created_by_id": 24870738,
"created_by_request_id": "worker:w:w:recurring_task_creator:parent-3952832467",
"recurrence_type": "day",
"recurrence_count": 1,
"due_date": "2018-06-06",
"completed": true,
"completed_at": "2018-06-19T14:52:28.644Z",
"completed_by_id": 24870738,
"starred": false,
"list_id": 350926181,
"revision": 2,
"title": "Turn on computer",
"type": "task"
}
I have 1 question
We use VSTS in our company. Now I want to require my developers to write unit tests to each project
My question is: If I can to build in Team Service Web Portal to require contain Unit tests, and if project doesn't has any unit tests - set build fail?
Thank you.
You can add a PowerShell task to check if the build project contains unit tests. Detail steps as below:
Add a PowerShell task after VS test task, and get VS test build log by timeline REST API. For TFS the rest api format should be:
GET http://{tsserver}:8080/tfs/{collection}/{project}/_apis/build/builds/{buildId}/timeline?api-version=3.0
Then search the log for VS test task, and you can get the detail VS test build log by the url. Such as below example, VS test task build log can be find in http://wxv-xindo-12r2:8080/tfs/DefaultCollection/5dfb8b33-9949-4187-9d09-474c8fe87238/_apis/build/builds/1477/logs/5.
{
"id": "c43e4f8f-3db9-4fdc-90c0-1153f165b9a9",
"parentId": "39d66172-979a-46e8-a04d-fe8e4e77da43",
"type": "Task",
"name": "Test Assemblies",
"startTime": "2018-05-25T02:31:11.177Z",
"finishTime": "2018-05-25T02:31:17.133Z",
"currentOperation": null,
"percentComplete": null,
"state": "completed",
"result": "succeeded",
"resultCode": null,
"changeId": 17,
"lastModified": "0001-01-01T00:00:00",
"workerName": "mypc",
"order": 5,
"details": null,
"errorCount": 0,
"warningCount": 2,
"url": null,
"log": {
"id": 5,
"type": "Container",
"url": "http://tfsserver:8080/tfs/DefaultCollection/5dfb8b33-9949-4187-9d09-474c8fe87238/_apis/build/builds/1477/logs/5"
},
"task": {
"id": "ef087383-ee5e-42c7-9a53-ab56c98420f9",
"name": "VSTest",
"version": "2.0.55"
},
"issues": [
{
"type": "warning",
"category": "General",
"message": "",
"data": {
"type": "warning",
"code": "002004"
}
},
{
"type": "warning",
"category": "General",
"message": "No test assemblies found matching the pattern: **\\release\\*test*.dll,!**\\obj\\**.",
"data": {
"type": "warning"
}
}
]
}
Then check if the VS test task has the warning:
[warning]No test assemblies found matching the pattern: '**\*test*.dll;-:**\obj\**'
If the VS test build log contains above warning, fail the PowerShell task by exit 1.
I'm trying to setup Teamcity building and verifying patchsets from Gerrit. The last step should set Verified to -1 if build failed. I'm playing around with Gerrit REST API and I think I found a proper command:
https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#set-review
The documentation says:
As response a ReviewInfo entity is returned that describes the applied
labels.
My request looks like this:
POST <gerrit-url>/a/changes/I696f00f4968fcb35fa614ce6325499aa15367150/revisions/current/review
{
"message": "Build failed",
"labels": {
"Verified": -1
}
}
As a response I get full revision info:
{
"id": "dev_test~master~<change-id>",
"project": "dev_test",
"branch": "master",
"hashtags": [],
"change_id": "<change-id>",
"subject": "a test",
"status": "NEW",
"created": "2017-04-03 07:53:19.000000000",
"updated": "2017-04-04 08:47:34.000000000",
"submit_type": "MERGE_IF_NECESSARY",
"mergeable": true,
"insertions": 133,
"deletions": 7,
"unresolved_comment_count": 0,
"_number": 381,
"owner": {
"_account_id": 4,
"name": "<my-name>",
"email": "<my-email>",
"username": "<my-username>",
},
"labels": {
"Code-Review": {
"all": [
{
"value": 1,
"date": "2017-04-04 08:47:34.000000000",
"permitted_voting_range": {
"min": -2,
"max": 2
},
"_account_id": 4,
"name": "<my-name>",
"email": "<my-email>",
"username": "<my-username>"
}
],
"values": {
"-2": "This shall not be merged",
"-1": "I would prefer this is not merged as is",
" 0": "No score",
"+1": "Looks good to me, but someone else must approve",
"+2": "Looks good to me, approved"
},
"default_value": 0
},
"Verified": {
"all": [
{
"value": 0,
"permitted_voting_range": {
"min": -1,
"max": 1
},
"_account_id": 4,
"name": "<my-name>",
"email": "<my-email>",
"username": "<my-username>"
}
],
"values": {
"-1": "Fails",
" 0": "No score",
"+1": "Verified"
},
"default_value": 0
}
},
"permitted_labels": {},
"removable_reviewers": [],
"reviewers": {
"REVIEWER": [
{
"_account_id": 4,
"name": "<my-name>",
"email": "<my-email>",
"username": "<my-username>"
}
]
},
"current_revision": "913330441711b067899a664a60c78be518e547b4",
"revisions": {
"913330441711b067899a664a60c78be518e547b4": {
"kind": "REWORK",
"_number": 6,
"created": "2017-04-03 14:08:14.000000000",
"uploader": {
"_account_id": 4,
"name": "<my-name>",
"email": "<my-email>",
"username": "<my-username>"
},
"ref": "refs/changes/81/381/6",
"fetch": {
"ssh": {
"url": "ssh://<url>",
"ref": "refs/changes/81/381/6"
},
"http": {
"url": "http://<url>",
"ref": "refs/changes/81/381/6"
}
}
}
}
}
It's not affected by request. Same response is returned when I send request using GET method or using POST method with invalid JSON in body(!)
Gerrit version is: 2.13.6-3008-gcdc381e
Do I something wrong?
PS. Here is similar question, but it isn't helpful: Gerrit set-review api doesn't work
EDIT:
It seems that I getting response from GET request not POST
I figured it out. It's not gerrit problem. I used http request and our server redirected to https with 301 which the Postman fallowed and returned response for GET request.
I did not find any documentation about the states of a MariaDB backup and the restore (https://docs.developer.swisscom.com/devguide-sc/services/backups.html).
For example, when I make the API call GET /custom/service_instances/{service-instance-id}/backups, the following JSON is returned as a response. In the response there are the attributes "status" in the entity of a backup, and the entity of a restore.
{
"total_results": 2,
"total_pages": 1,
"prev_url": null,
"next_url": null,
"resources": [
{
"metadata": {
"guid": "95b9108a-1903-4cea-b52e-bbb3b0414986",
"url": "/custom/service_instances/3955ad28-3f47-4f08-8eee-748f6e162d46/backups/95b9108a-1903-4cea-b52e-bbb3b0414986",
"created_at": "2016-10-03T20:52:04Z",
"updated_at": "2016-10-03T20:52:34Z"
},
"entity": {
"service_instance_id": "3955ad28-3f47-4f08-8eee-748f6e162d46",
"status": "CREATE_SUCCEEDED",
"restores": []
}
},
{
"metadata": {
"guid": "4ffff7d4-55a8-4e57-9035-98ed11380991",
"url": "/custom/service_instances/3955ad28-3f47-4f08-8eee-748f6e162d46/backups/4ffff7d4-55a8-4e57-9035-98ed11380991",
"created_at": "2016-10-03T08:50:07Z",
"updated_at": "2016-10-03T08:50:37Z"
},
"entity": {
"service_instance_id": "3955ad28-3f47-4f08-8eee-748f6e162d46",
"status": "CREATE_SUCCEEDED",
"restores": [
{
"metadata": {
"guid": "1a33a385-3703-423d-8052-be7a7a061878",
"url": "/custom/service_instances/3955ad28-3f47-4f08-8eee-748f6e162d46/backups/4ffff7d4-55a8-4e57-9035-98ed11380991/restores/1a33a385-3703-423d-8052-be7a7a061878",
"created_at": "2016-10-03T20:52:38Z",
"updated_at": "2016-10-03T20:53:08Z"
},
"entity": {
"backup_id": "4ffff7d4-55a8-4e57-9035-98ed11380991",
"status": "SUCCEEDED"
}
}
]
}
}
]
}
So, the question is: WHAT are all possible values in the "status" attributes on both cases, and WHEN do they happen?
Thanks in advance,
Just for documentation purposes, I've got to know which are the available statuses:
Backup statuses:
CREATE_IN_PROGRESS
CREATE_SUCCEEDED
CREATE_FAILED
DELETE_IN_PROGRESS
DELETE_SUCCEEDED
DELETE_FAILED
Restore statuses:
IN_PROGRESS
SUCCEEDED
FAILED
Moreover, it is not possible to trigger a restore when there is another backup create or delete, or another restore operation in progress.