如何将Bamboo构建日志压缩为工件供远程用户快速下载?
Got it, let's sort this out for your team in India—compressing those build logs into artifacts will absolutely slash their download wait times. Here are two straightforward, reliable ways to set this up in Bamboo:
Method 1: Combine a Script Task + Archive Artifacts Task
This is the most flexible approach, especially if you want clear separation between compression and archiving steps.
Add a Script Task to your build stage (place it after your main build tasks, right before you archive artifacts):
- For Linux/macOS agents, use this bash script to compress all logs into a single tar.gz file:
# Compress the entire build log directory into a compressed archive tar -czf ${bamboo.build.working.directory}/build-logs.tar.gz -C ${bamboo.build.log.dir} . - For Windows agents, use this PowerShell script to create a zip file:
# Compress all log files into a zip archive (overwrite if it exists) Compress-Archive -Path "${bamboo.build.log.dir}\*" -DestinationPath "${bamboo.build.working.directory}\build-logs.zip" -Force
Note: We use
${bamboo.build.log.dir}(Bamboo's built-in variable) to target the exact log directory, so this works no matter where your agent is running.- For Linux/macOS agents, use this bash script to compress all logs into a single tar.gz file:
Add an Archive Artifacts Task right after the script task:
- In the "Artifacts to archive" field, enter the path to your compressed file:
build-logs.tar.gz(orbuild-logs.zipfor Windows). - You can also set a friendly name like "Compressed Build Logs" so your team knows exactly what they're downloading.
- In the "Artifacts to archive" field, enter the path to your compressed file:
Method 2: Use a Post-build Script to Handle Everything in One Step
If you prefer fewer tasks, you can handle compression and artifact registration in a single post-build script:
- Go to your build plan's Post-build Actions and add a Run script action.
- Use the appropriate script for your agent OS:
- Linux/macOS:
# Compress logs and create a file listing the artifact for Bamboo to pick up tar -czf ${bamboo.build.working.directory}/build-logs.tar.gz -C ${bamboo.build.log.dir} . echo "build-logs.tar.gz" >> ${bamboo.build.working.directory}/artifacts.txt - Windows:
Compress-Archive -Path "${bamboo.build.log.dir}\*" -DestinationPath "${bamboo.build.working.directory}\build-logs.zip" -Force Add-Content -Path "${bamboo.build.working.directory}\artifacts.txt" -Value "build-logs.zip"
- Linux/macOS:
- Add an Archive Artifacts Task and set "Artifacts to archive" to
@artifacts.txt—Bamboo will read this file to know which compressed log to store as an artifact.
Pro Tips for Optimal Results
- Choose the right compression format:
tar.xzhas a higher compression ratio thantar.gz(smaller file size) but takes a bit longer to compress/decompress. If download speed is your top priority, it's worth the tradeoff. - Verify permissions: Make sure your Bamboo agent has read access to
${bamboo.build.log.dir}and write access to${bamboo.build.working.directory}(this is usually enabled by default, but it's good to double-check if you run into errors). - Test with a small build: Run a test build first to confirm the compressed artifact is generated correctly and that your team can download and extract it without issues.
内容的提问来源于stack exchange,提问作者Jason Templeman

