Capturing pipeline logs in the YAML file

Shyam Kumar 916 Reputation points
2025-05-23T09:40:23.53+00:00

I am looking to access or download the pipeline logs generated by my Azure DevOps YAML pipeline. Is there a standard location where these logs are stored, or a recommended procedure to capture or download them from within the YAML file itself?

Azure DevOps

Answer accepted by question author
Durga Reshma Malthi 11,600 Reputation points Microsoft External Staff Moderator
2025-05-23T10:48:05.23+00:00

Hi Diptesh Kumar

Here’s how you can access and download these logs:

  1. After completion of Azure Pipeline -> Open the Pipeline -> Click on 3 dots -> select the Download logs option to access the logs. User's image
  2. If you want to store logs within the pipeline run itself, you can archive them as artifacts, by following the below steps in the yaml file.
       steps:
         - task: SqlAzureDacpacDeployment@1
           inputs:
             azureSubscription: 'YourServiceConnection'
             ServerName: 'your-sql-server.database.windows.net'
             DatabaseName: 'your-database'
             deployType: 'SqlTask'
             sqlFile: '$(System.DefaultWorkingDirectory)/scripts/deployment.sql'
         - task: PublishBuildArtifacts@1
           displayName: 'Upload SQL Deployment Logs'
           inputs:
             pathToPublish: '$(Agent.TempDirectory)'
             artifactName: 'SqlDeploymentLogs'
    
    After completion of pipeline, you can see in the Artifacts section and click on download artifacts User's image
  3. In order to get the debug logs, in additional arguments of task, add -verbose or '/Diagnostics:True'
       - task: SqlAzureDacpacDeployment@1
         displayName: 'test'
         inputs:
            azureSubscription: "test"
            AuthenticationType: 'servicePrincipal'
            Servername: '$(ServerName)'
            DatabaseName: '$(DatabaseName)'
            deployType: 'SqlTask'
            SqlFile: 'test.sql'
            sqlAdditionalArguments: '-verbose' #(or) '/Diagnostics:True'
    
  4. Or else if you want to capture the output of a specific command or task, you can redirect the output to a file which allows you to download.
       trigger:
         branches:
           include:
             - main
       pool:
         vmImage: 'windows-latest'
       jobs:
       - job: Deploy
         steps:
         - task: SqlAzureDacpacDeployment@1
           inputs:
             azureSubscription: 'your-service-connection'
             ServerName: 'your-server-name'
             DatabaseName: 'your-database-name'
             DacpacFile: '$(System.DefaultWorkingDirectory)/path/to/your.dacpac'
             SqlFile: '$(System.DefaultWorkingDirectory)/path/to/your.sql'
             PublishProfile: '$(System.DefaultWorkingDirectory)/path/to/your.publish.xml'
             AdditionalArguments: '/p:LogFile=$(System.DefaultWorkingDirectory)/logs/deployment.log'
         - publish: $(System.DefaultWorkingDirectory)/logs/deployment.log
           artifact: deployment-logs
    

Please refer this doc for more information: Review Logs

Additional References:

https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/logs/get?view=azure-devops-rest-7.1

https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/sql-azure-dacpac-deployment-v1?view=azure-pipelines

Hope this helps!

Please Let me know if you have any queries.

Was this answer helpful?

1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Durga Reshma Malthi 11,600 Reputation points Microsoft External Staff Moderator
    2025-05-26T07:49:57.49+00:00

    Hi Diptesh Kumar

    Yes, that is the path when you create hosted agent on windows.

    For self-hosted agents, logs are typically stored in the _diag folder within the agent's root directory. You can access this folder to retrieve logs while the pipeline is running. These logs are related to Agent Diagnostic logs. Eg: C:\agent\_diag

    Logs are stored in the the agent’s root directory: C:\agent\_work or C:\azuredevops-agent\_work

    Default path on self-hosted Windows agents:

    <agent_root>\_work\<pipeline_id>\s

    <agent_root>\_work\<pipeline_id>\a

    <agent_root>\_work\<pipeline_id>\_temp

    <agent_root>\_work\<pipeline_id>\logs

    You can refer this doc: Agents and Agent Pools for more information.

    Additional References:

    https://stackoverflow.com/questions/52057680/where-are-the-vsts-logs-on-a-self-hosted-azure-devops-build-agent

    https://stackoverflow.com/questions/64455815/how-to-find-the-pipeline-log-on-the-localhost

    Hope this helps!

    Please Let me know if you have any queries.

    If you found the information helpful, please click "Upvote" on the post to let us know and consider accepting the answer as the token of appreciation. Thank You.

    Was this answer helpful?

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.