Generate support logs

Still need help?

The Atlassian Community is here for you.

Ask the community

If you hit an issue using pipelines, the logs can give you great information on what might be happening. Rather than try and read through all the logs created you can use the power of artifacts to create specific logs, which you can then download. 

For example you can get a snapshot of what processes are running in your pipeline by adding the lines below to your bitbucket-pipelines.yml. This is useful if you’re trying to see if a process has hung or is using too much memory.

bitbucket-pipelines.yml
pipelines:
  default:
    - step:
        artifacts:
          - process-logs.txt #declaring that you want to keep this as an artifact
        script:
          - while true; do date && ps aux && echo "" && sleep 30; done >> process-logs.txt &
          - # The rest of the script.

This will log the process information the process-logs.txt file, instead of the build logs.

Once the pipeline step completes, you can download the artifact from the Artifacts tab on the Result Page.

Other examples

Container memory monitoring

This is useful if you are getting out of memory errors, or to check on how much memory your pipeline uses:

bitbucket-pipelines.yml
pipelines:
  default:
    - step:
        artifacts:
          - memory-logs.txt
        script:
          - while true; do date && echo -n "Memory usage in megabytes:" && echo $((`cat /sys/fs/cgroup/memory/memory.memsw.usage_in_bytes | awk '{print $1}'`/1048576)) && echo "" && sleep 30; done >> memory-logs.txt &
          - # The rest of the script.

Docker events

If you’d like to collect more information about your Docker events, you can log the output of the docker events command:

bitbucket-pipelines.yml
pipelines:
  default:
    - step:
        services:
          - docker
        artifacts:
          - docker-event-logs.txt
        script:
          - docker events >> docker-event-logs.txt &
          - # The rest of the script.

Combined logs

You can set up a selection of logs at the same time. This example shows 3 logs being extracted.

bitbucket-pipelines.yml
pipelines:
  default:
    - step:
        services:
          - docker
        artifacts:
          - process-logs.txt
          - memory-logs.txt
          - docker-event-logs.txt
        script:
          - while true; do date && ps -aux && sleep 30 && echo ""; done >> process-logs.txt &
          - while true; do date && echo -n "Memory usage in megabytes:" && echo $((`cat /sys/fs/cgroup/memory/memory.memsw.usage_in_bytes | awk '{print $1}'`/1048576)) && echo "" && sleep 30; done >> memory-logs.txt &
          - docker events >> docker-event-logs.txt &
          - # The rest of the script.

Build Your Own

These examples are just the beginning. You can combine a variety of system commands to get detailed logs for your situation. We recommend that for ease of viewing and to avoid artifact size limits, that you keep the size of log files below 1GB.

Notes

While secured variables output in the UI logs are always masked, if you need to investigate any variables, do not redirect secured variables to a file. Redirecting secured variables to a file will reveal them.

For more information about artifacts, check out our documentation.

Last modified on Sep 30, 2022

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.