TFS/VSTS vNext Build and Release Logs Location - azure-devops

Are the build and release logs saved locally on the Build Agent machine? I know that I can manually click on the "Download all logs as zip" link for each build and release, but if I want to automatically send these logs to someone else (or bulk send them), is there another way to find them (either on the Build Agent machine or in the database somewhere)?
Thanks!

Both for TFS and VSTS, the build/release logs are located in TFS/VSTS server (no business with what the agent is used).
In build/release retention, you can set the policies to keep the builds/releases. And it default keep the latest 30 days' builds and releases.
Except the way to click "Download all logs as zip" button to get a build/release logs, you can also get build/release logs by REST API. Such as below example:
GET https://account.visualstudio.com/DefaultCollection/Git2/_apis/build/builds/2373/timeline?api-version=2.0
And you can get each build step log in the response, such as:
{
"records": [
{
"id": "d2c6b274-40fe-4727-85b6-eb92fb4f6009",
"parentId": "ff7265dc-abe3-5e6a-6194-76bb88f00044",
"type": "Task",
"name": "Initialize Job",
"startTime": "2018-01-15T05:30:25.6Z",
"finishTime": "2018-01-15T05:30:26.0233333Z",
"currentOperation": null,
"percentComplete": null,
"state": "completed",
"result": "succeeded",
"resultCode": null,
"changeId": 8,
"lastModified": "0001-01-01T00:00:00",
"workerName": "V-myPC",
"order": 2,
"details": null,
"errorCount": 0,
"warningCount": 0,
"url": null,
"log": {
"id": 2,
"type": "Container",
"url": "https://account.visualstudio.com/DefaultCollection/f7855e29-6f8d-429d-8c9b-41fd4d7e70a4/_apis/build/builds/2373/logs/2"
},
"task": null
},
...
],
"lastChangedBy": "00000002-0000-8888-8000-000000000000",
"lastChangedOn": "2018-01-15T05:30:40.947Z",
"id": "4b4280d4-5358-4238-ab95-d44475c92bc9",
"changeId": 19,
"url": "https://account.visualstudio.com/DefaultCollection/f7855e29-6f8d-429d-8c9b-41fd4d7e70a4/_apis/build/builds/2373/Timeline/4b4280d4-5358-4238-ab95-d44475c92bc9"
}
As the above response, you can find the Initialized Job step by the url https://account.visualstudio.com/DefaultCollection/f7855e29-6f8d-429d-8c9b-41fd4d7e70a4/_apis/build/builds/2373/logs/2.

Related

Azure Devops / Kudusync deploys wrong package to Azure Function

We have two Azure functions, let's call them A and B, that we deploy using Azure Devops. Looking at the deployment logs, first the right package is deployed followed by a deploy where the contents of Function App A are deployed to Function app B. How this happens is a mystery.
The strange things is, looking at the logs and what is inside Kudu, they don't match up. For example, the latest deploy logs will say this:
[
{
"log_time": "2021-09-17T10:57:17.3180234Z",
"id": "",
"message": "Command: \"D:\\home\\site\\deployments\\tools\\deploy.cmd\"",
"type": 0,
"details_url": null
},
{
"log_time": "2021-09-17T10:57:18.5999063Z",
"id": "",
"message": "Handling Basic Web Site deployment.",
"type": 0,
"details_url": null
},
{
"log_time": "2021-09-17T10:57:24.8723981Z",
"id": "",
"message": "Creating app_offline.htm",
"type": 0,
"details_url": null
},
{
"log_time": "2021-09-17T10:57:24.9036384Z",
"id": "",
"message": "KuduSync.NET from: 'D:\\local\\Temp\\zipdeploy\\extracted' to: 'D:\\home\\site\\wwwroot'",
"type": 0,
"details_url": null
},
{
"log_time": "2021-09-17T10:57:25.0941627Z",
"id": "",
"message": "Deleting file: 'OurCompany.Api.B.dll'",
"type": 0,
"details_url": null
},
"log_time": "2021-09-17T10:57:25.1557977Z",
"id": "",
"message": "Copying file: 'extensions.json'",
"type": 0,
"details_url": null
},
{
"log_time": "2021-09-17T10:57:25.1718472Z",
"id": "",
"message": "Copying file: 'OurCompany.Api.A.dll'",
"type": 0,
"details_url": null
},
{
"log_time": "2021-09-17T10:57:27.4441118Z",
"id": "",
"message": "Deleting app_offline.htm",
"type": 0,
"details_url": null
},
{
"log_time": "2021-09-17T10:57:27.5223301Z",
"id": "",
"message": "Finished successfully.",
"type": 0,
"details_url": null
}
]
But when I go to Kudu on the server of the OurCompany.Api.B function app and I look at the actual contents in D:\\local\\Temp\\zipdeploy\\extracted I see no OurCompany.Api.A.dll - only OurCompany.Api.B.dll. Note that the timestamp of the files in the extracted folder predate the second deployment, so they are from the first and CORRECT deploy.
If I look at the contents inside D:\\home\\site\\wwwroot I DO see the incorrect OurCompany.Api.A.dll but where this is coming from I have no idea.
So... how can the deploy logs mention the copying of incorrect dll files while they are not in the folder on the server, and never were there because the timestamps don't add up? We've been working on this issue for days now without succes.
Apparantly this is happening because both Functions are hosted on the same App Service plan and thus using the same Azure File Share. See this thread https://github.com/projectkudu/kudu/issues/3333.

Azure DevOps API get status of previous release task

Does anyone know the api to get the status of the individual release task in a release?
I can get the status of the release itself but not the individual release tasks (PowerShell tasks in my case). https://learn.microsoft.com/en-us/rest/api/azure/devops/release/releases/get%20release?view=azure-devops-rest-6.0
Also if anyone knows where the source code is for ADO built in tasks condition. can you please share the link?
Does anyone know the api to get the status of the individual release task in a release?
Method 1: You can use a REST API that is not documented:
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/Release/releases/{releaseId}/environments/{environmentId}/attempts/{attemptId}/timelines/{timelineId}/tasks
It returns a brief overview and status(succeeded, inProgress, pending, failed...) of all tasks in the release.
The response body looks like the following example:
{
"count": 9,
"value": [
{
"id": 4,
"timelineRecordId": "d81751cc-e42f-407a-9091-f611d37df33b",
"name": "Initialize job",
"dateStarted": "2021-04-27T06:01:21.5233333Z",
"dateEnded": "2021-04-27T06:01:23.32Z",
"startTime": "2021-04-27T06:01:21.5233333Z",
"finishTime": "2021-04-27T06:01:23.32Z",
"status": "succeeded",
"rank": 1,
"lineCount": 121,
"issues": [],
"agentName": "Hosted Agent",
"logUrl": "https://vsrm.dev.azure.com/{organization}/{project}/_apis/Release/releases/6/environments/6/deployPhases/6/tasks/4/logs"
},
{
"id": 5,
"timelineRecordId": "68716c38-638d-551b-6964-2da9e273edef",
"name": "Command Line Script",
"dateStarted": "2021-04-27T06:01:23.33Z",
"dateEnded": "2021-04-27T06:01:28.5833333Z",
"startTime": "2021-04-27T06:01:23.33Z",
"finishTime": "2021-04-27T06:01:28.5833333Z",
"status": "succeeded",
"rank": 2,
"lineCount": 15,
"issues": [],
"task": {
"id": "d9bafed4-0b18-4f58-968d-86655b4d2ce9",
"name": "CmdLine",
"version": "2.182.0"
},
"agentName": "Hosted Agent",
"logUrl": "https://vsrm.dev.azure.com/{organization}/{project}/_apis/Release/releases/6/environments/6/deployPhases/6/tasks/5/logs"
},
{
"id": 6,
"timelineRecordId": "fced85f1-31cf-59f2-d2e0-ccd1645b2427",
"name": "Command Line Script",
"dateStarted": "2021-04-27T06:01:28.5866667Z",
"startTime": "2021-04-27T06:01:28.5866667Z",
"status": "inProgress",
"percentComplete": 0,
"rank": 3,
"issues": [],
"task": {
"id": "d9bafed4-0b18-4f58-968d-86655b4d2ce9",
"name": "CmdLine",
"version": "2.182.0"
},
"agentName": "Hosted Agent",
"logUrl": ""
}
]
}
Method 2: You can use the REST API Releases - Get Task Log:
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}/environments/{environmentId}/deployPhases/{releaseDeployPhaseId}/tasks/{taskId}/logs?api-version=6.0-preview.2
It returns the running log of a specific task.
The response body looks like the following example:
2021-04-27T05:50:50.3443852Z ##[section]Starting: Command Line Script
2021-04-27T05:50:50.4313144Z ==============================================================================
2021-04-27T05:50:50.4313918Z Task : Command line
2021-04-27T05:50:50.4314555Z Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
2021-04-27T05:50:50.4314878Z Version : 2.182.0
2021-04-27T05:50:50.4315342Z Author : Microsoft Corporation
2021-04-27T05:50:50.4315927Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
2021-04-27T05:50:50.4316336Z ==============================================================================
2021-04-27T05:50:53.2219858Z Generating script.
2021-04-27T05:50:53.2572235Z ========================== Starting Command Output ===========================
2021-04-27T05:50:53.2972287Z ##[command]"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\fda7641b-b8a2-4d04-8f83-94f5eda9c3b6.cmd""
2021-04-27T05:50:53.3085688Z Write your commands here
2021-04-27T05:50:53.3086888Z Hello world
2021-04-27T05:50:53.3788822Z ##[section]Finishing: Command Line Script
If anyone knows where the source code is for ADO built in tasks condition.
I don't think Azure DevOps built-in tasks have conditions source code, because conditions can be used not only for built-in tasks, but for other tasks, jobs, stages, etc... It is supported by YAML Schema and Azure DevOps classic UI pipeline, but it has nothing to do with specific tasks.
Click this github link for Azure DevOps built-in task source code.
Each of your PowerShell tasks is an environment; therefore, you can access through the environments that is returned by "Get Release" API. See https://learn.microsoft.com/en-us/rest/api/azure/devops/release/releases/get%20release?view=azure-devops-rest-6.0#releaseenvironment

Where can I find System.TeamProjectId for a project in Azure Devops

I need this Id upfront but I can't seem to find it anywhere online?
The documentation only refers to it as a system variable.
Context:
I have multiple projects and I want to identify a project during CI so it can run a powershell script hosted in another repository.
You can get the all team projects id with REST Api:
https://dev.azure.com/{organization}/_apis/projects?api-version=5.0-preview.3
Results:
{
"count": 3,
"value": [
{
"id": "eb6e4656-77fc-42a1-9181-4c6d8e9da5d1",
"name": "Fabrikam-Fiber-TFVC",
"description": "Team Foundation Version Control projects.",
"url": "https://dev.azure.com/fabrikam/_apis/projects/eb6e4656-77fc-42a1-9181-4c6d8e9da5d1",
"state": "wellFormed"
},
{
"id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
"name": "Fabrikam-Fiber-Git",
"description": "Git projects",
"url": "https://dev.azure.com/fabrikam/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c",
"state": "wellFormed"
},
{
"id": "281f9a5b-af0d-49b4-a1df-fe6f5e5f84d0",
"name": "TestGit",
"url": "https://dev.azure.com/fabrikam/_apis/projects/281f9a5b-af0d-49b4-a1df-fe6f5e5f84d0",
"state": "wellFormed"
}
]
}
You don't even need use Postman or create Http request, just enter the API url above in the browser.
You can examine the HTML in the UI of the dashboard on your organisation projects page:

Require build to Contain Unit tests VSTS

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.

How to get reason for failure of a previous task in vsts CI build

Is there a way to get the reason for a previous task failing so I can use it in a later task. Right now I'm naming and shaming who ever breaks the build and linking to the commit that did it in slack. But you can't tell why it broke unless you go to vsts and look at the logs.
I didn't see any build variables that get set on failures. Right now the only thing I can think of is to route stderr to a file and the console and then on failure read that file into a variable. But that seems hacky.
After the task which you want to get the detail failed reason, you can add a PowerShell task to get the previous tasks’ details by Rest API.
Detail steps in the PowerShell task:
1. Execute the rest API to get all the previous build tasks’ details.
2. Search the failed task by task name or build result. An you can get the task’s detail as
{
"id": "b75e0dd2-9734-4e83-ab5b-dc6001ea037c",
"parentId": "78e591b0-98f5-4d8a-a46c-417fda2c36dc",
"type": "Task",
"name": "Run cd ",
"startTime": "2017-08-28T05:33:51.86Z",
"finishTime": "2017-08-28T05:33:53.053Z",
"currentOperation": null,
"percentComplete": null,
"state": "completed",
"result": "failed",
"resultCode": null,
"changeId": 12,
"lastModified": "0001-01-01T00:00:00",
"workerName": "machine",
"order": 4,
"details": null,
"errorCount": 1,
"warningCount": 0,
"url": null,
"log": {
"id": 3,
"type": "Container",
"url": "https://account.visualstudio.com/DefaultCollection/f7855e29-6f8d-429d-8c9b-41fd4d7e70a4/_apis/build/builds/1339/logs/3"
}
3. Then you can get the detail failed logs in the url option (as the
url https://account.visualstudio.com/DefaultCollection/f7855e29-6f8d-429d-8c9b-41fd4d7e70a4/_apis/build/builds/1339/logs/3 in above example).