Generate support logs in Bitbucket Cloud Pipelines
プラットフォームの注記: Cloud のみ - This article only applies to Atlassian apps on the クラウド プラットフォーム上のアトラシアン製品にのみ適用されます。
要約
This KB covers generating support logs in Bitbucket Pipelines using artifacts to troubleshoot issues and monitor processes effectively.
Using artifacts
If you encounter an issue using pipelines, the logs can give you great information on what might happen. Rather than try to 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 to process-logs.txt file, instead of the build logs.
パイプライン ステップが完了すると、[結果] ページの [アーティファクト] タブからアーティファクトをダウンロードできます。
Please remember that artifacts have a size limit of 1 GB and are stored for 14 days after executing the step that produced them. After this time, artifacts are no longer available.
ソリューション
その他の例
コンテナ メモリの監視
これは、メモリ不足エラーが発生している場合や、パイプラインが使用しているメモリの量を確認する場合に役立ちます。
bitbucket-pipelines.yml
pipelines:
default:
- step:
artifacts:
- memory-logs.txt
script:
- while true; do echo "Memory usage in megabytes:" && echo $((`cat /sys/fs/cgroup/memory.current | awk '{print $1}'`/1048576)) && echo "" && sleep 30; done >> memory-logs.txt &
- # The rest of the script.Docker イベント
Docker イベントに関する情報を収集したい場合、docker events コマンドの出力をログに記録できます。
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.ログの結合
選択した複数のログを同時にセットアップすることができます。この例では、3 つのログを抽出しています。
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 echo "Memory usage in megabytes:" && echo $((`cat /sys/fs/cgroup/memory.current | awk '{print $1}'`/1048576)) && echo "" && sleep 30; done >> memory-logs.txt &
- docker events >> docker-event-logs.txt &
- # The rest of the script.自身での構築
These examples are just the beginning. You can combine a variety of system commands to get detailed logs for your situation. We recommend keeping the log file size below 1GB for ease of viewing and to avoid artifact size limits.
注意
While secured variables output in the UI logs are always masked, if you need to investigate any variables, don't redirect them to a file. Redirecting them to a file will reveal them.
アーティファクトの詳細については、ドキュメントを参照してください。
この内容はお役に立ちましたか?