How to save build logs from Bitbucket Pipelines?
Asked by ethan.chen:

Currently, the way I have my pipelines setup is having each step run on 'self.hosted' runners. I do it this way so I don't have to spend Bitbucket build minutes. Every time the pipeline runs, I can see the containers being created and terminated on my Docker application. The only debugging method I have found is by clicking on the container with the "build" word in it. Inside the container, I can see all the logs; every project build step and tests. I'm trying to find a way to save these build logs into a text file and download it as an artifact.


Answers:
author: Theodora Boudale
body: Hi [@ethan.chen](/t5/user/viewprofilepage/user-id/4538557) and welcome to the community.

Even when you run builds on your local runner, you can still view the builds and their logs in the Pipelines page of the repo on Bitbucket website.

If you select a build in there, you can view the logs of each step. In the top right corner of the step's log there is a **download icon** that allows you to download the logs for that step as a text file (it's the icon with a cloud and arrow):

![Screenshot 2021-11-08 at 17.31.54.png](https://community.atlassian.com/t5/image/serverpage/image-id/168377iA8153249CF5EB751/image-size/large?v=v2&px=999 "Screenshot 2021-11-08 at 17.31.54.png")

If you're looking for a way to do this via API, we have the following endpoint:

* <https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pipelines/%7Bpipeline_uuid%7D/steps/%7Bstep_uuid%7D/log>

Please feel free to let me know if you have any questions.

Kind regards,  
Theodora

comments: author: ethan.chen
body: [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) Thank you for the reply! I was able to download the logs with that button but it doesn't seem to be complete. All I see is the runner's log; not the ones from build (where dotnet is installed and project is tested.).

![Capture.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/168415i403CDC486C926808/image-size/large?v=v2&px=999 "Capture.PNG")(from Docker)


author: Theodora Boudale
body: Hi [@ethan.chen](/t5/user/viewprofilepage/user-id/4538557),

I'm not really sure which logs you are missing. Does your bitbucket-pipelines.yml file perhaps have multiple steps that run on your local runner?

The log I mentioned in my previous reply is the log of a single step. Selecting the download icon will download the log for this step only.

If your build has multiple steps, you can select each step and then download the logs of this step.  
E.g. see below a screenshot from the page of a Pipelines build that has two steps:

![Screenshot 2021-11-09 at 09.50.11.png](https://community.atlassian.com/t5/image/serverpage/image-id/168500i58D61F7480C4D3B8/image-size/large?v=v2&px=999 "Screenshot 2021-11-09 at 09.50.11.png")

The panel titled 'Pipeline' lists all steps of that build, in that case, I have a step named "Build \& Test" and then another step named "Deploy". When you open the page of a Pipelines build, the first step is selected. If you want to view and download the log of the second step, you can select the second step from that panel and download its logs using the same icon.

If this is not what you're looking for, could you please share some more details and/or an example of what is missing?

Kind regards,  
Theodora


Tags: bitbucket-pipelines