Generate support logs
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.
たとえば、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.
これによって、ビルド ログではなく process-logs.txt ファイルにプロセス情報が記録されます。
パイプライン ステップが完了すると、[結果] ページの [アーティファクト] タブからアーティファクトをダウンロードできます。
その他の例
コンテナ メモリの監視
これは、メモリ不足エラーが発生している場合や、パイプラインが使用しているメモリの量を確認する場合に役立ちます。
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 イベント
If you’d like to collect more information about your Docker events, you can log the output of the docker events command:
pipelines:
default:
- step:
services:
- docker
artifacts:
- docker-event-logs.txt
script:
- docker events >> docker-event-logs.txt &
- # The rest of the script.
ログの結合
選択した複数のログを同時にセットアップすることができます。この例では、3 つのログを抽出しています。
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.
自身での構築
ここまでで紹介したものは、ほんの一例に過ぎません。さまざまなシステム コマンドを組み合わせて、状況に応じて詳細なログを取得できます。参照時の取り扱いや、アーティファクトのサイズ制限の回避を考慮し、ログ ファイルのサイズは 1 GB 未満に維持することをお勧めします。
注意
保護されている変数の UI ログへの出力は常にマスクされます。変数を調査する必要がある場合、保護されている変数をファイルにリダイレクトしないでください。保護されている変数をファイルにリダイレクトした場合、マスキングは行われません。
For more information about artifacts, check out our documentation.