4

私たちは、統合テストのための共有データベースが少なく、これらを共有する多数のブランチがあります。 Bambooが同じデータベースを使用する複数のブランチを同時に実行しないようにする方法はありますか?バンブーリミットのブランチ間の同時ビルド

複数のブランチを並列にビルドすると、互いが壊れて失敗します。

答えて

6

このBAM-12071およびBAM-2423には、ソリューションを実装するためにAtlassianが待機しているという傑出した機能要求があります。

一方、我々は古い形式のファイル(実際にはディレクトリ)のロックを使用することに基づいて、このための迅速で汚れた回避策を考案しました。各リソースは、ジョブまたはブランチ構成の変数名gatekeeper.resourceで定義されます。ビルドプロセスの開始時に、「ゲートキーパー」ステージは、共通サーバー上の共通ファイル内のディレクトリ名を使用して、必要なリソースが空き状態であることを確認します。ディレクトリ名が存在する間、リソースは使用中です。後続のビルド・ステージの最初のタスクは、リソース名を空のディレクトリとして作成し、最後のタスクはそれを削除します。他のビルドは、リソースが空き状態になるまで、第1段階を過ぎて進み、並行ビルドを停止することはできません。欠点は、それが地元の竹のエージェントを結びつけることであり、完全に確実ではありませんが、99%の時間で働いています。リソース変数が正しく定義されている場合は、ビルド計画全体で機能します。

Linuxのインスタンスに対してSSHタスクとして定義され、その:

# This Gatekeeper stage prevents concurrent builds against a resource 
# by looking for a directory instance in a common file area. 
# If the directory exists the build cannot proceed until it disappears. 
# The build sleeps as long as the directory exists. 
# 
# The first task in the subsequent stage is to create the directory, and 
# a final task in the build removes it. 
# As a failsafe a background half-hourly cron job should remove lock 
# dirs if they exceed 3 x the build time. 
######################################################### 
# Wait for a random number of seconds 20-120 to reduce (but not eliminate) the chance that multiple competing branch 
# builds triggered by timers both see the dir gone and start the unit test job at once and then proceed to clobber each other (i.e a race condition) 
# note: bamboo expects output every 3 minutes so do not increase beyond 180 seconds 
SLEEPYTIME=$(((RANDOM % 100) + 20)) 
echo SLEEPYTIME today is $SLEEPYTIME 
sleep $SLEEPYTIME 
# Wait for the Gatekeeper lock dir to disappear... or be older than 3 hours (previous build may have hung) 
file=/test/atlassian/bamboo-gatekeeper/inuse-${bamboo.gatekeeper.resource} 
while [ -d "$file" ] 
do 
    echo $(date +%H:%M:%S) waiting $SLEEPYTIME seconds... 
    sleep $SLEEPYTIME 
done 
exit 0 

(ゲートキーパー後)ビルドステージの最初のジョブのタスク:

# This will fail if the lock file (actually a directory!) already exists 
file=/test/atlassian/bamboo-gatekeeper/inuse-${bamboo.gatekeeper.resource} 
mkdir "$file" 

ビルド段階の最終ステップ以下ビルド(成功またはその他)

file=/test/atlassian/bamboo-gatekeeper/inuse-${bamboo.gatekeeper.resource} 
rm -rf "$file" 

フェールセーフcronクリーンアップt数時間以上経過したリソースゲートウェイディレクトリを削除するかどうかを尋ねる(この例では3つ)。必要ではありませんが、最後のタスクを実行せずにbamboo自体を再起動した場合、ビルドが無期限に縛られるのを防ぎます。

# This works in conjunction with bamboo unit tests. It clears any unit test lock files after 3 hours (e.g. build has hung or killed without removing lock file) 
15,45 * * * * find /test/atlassian/bamboo-gatekeeper -name inuse* -mmin +180 -delete 

gatekeeper.resourceは、任意の名前として定義できます。ここでは、統合テストで使用されるデータベーススキーマです。いくつかのブランチは共通のテスト環境を使用し、他のブランチは独自のインスタンスを持っています。このソリューションは、共通環境を使用してブランチを停止し、同時に実行することを中止します。

同時ビルドを特定の数に制限する完全な修正はありませんが、Atlassianが永続的なソリューションを実装するまでは、この問題を回避するだけで十分です。私はそれが他人を助けることを望む。

関連する問題