Concurrency 竹子可以跨越树枝

Concurrency 竹子可以跨越树枝,concurrency,resources,continuous-integration,integration-testing,bamboo,Concurrency,Resources,Continuous Integration,Integration Testing,Bamboo,我们有少量用于集成测试的共享数据库和大量共享这些数据库的分支。有没有办法防止Bambol同时尝试运行使用同一数据库的多个分支 当多个分支中的构建并行运行时,它们会相互碰撞并失败。对此有一些未解决的功能请求,正在等待Atlassian实施解决方案 同时,我们设计了一个快速而肮脏的解决方法,基于使用老式的文件(实际上是目录)锁定。每个资源都定义了一个变量名gatekeeper。在作业或分支配置中,在构建过程开始时,“gatekeeper”阶段使用公共服务器上公共文件中的目录名检查所需资源是否可用。当

我们有少量用于集成测试的共享数据库和大量共享这些数据库的分支。有没有办法防止Bambol同时尝试运行使用同一数据库的多个分支


当多个分支中的构建并行运行时,它们会相互碰撞并失败。

对此有一些未解决的功能请求,正在等待Atlassian实施解决方案

同时,我们设计了一个快速而肮脏的解决方法,基于使用老式的文件(实际上是目录)锁定。每个资源都定义了一个变量名
gatekeeper。在作业或分支配置中,在构建过程开始时,“gatekeeper”阶段使用公共服务器上公共文件中的目录名检查所需资源是否可用。当目录名存在时,资源正在使用中。后续构建阶段的第一个任务将资源名称创建为空目录,最后一个任务将其删除。在资源空闲并停止并发生成之前,其他生成无法继续通过第一阶段。不利的一面是,它确实与当地的竹子代理商有牵连,而且不是完全万无一失的,但在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
构建阶段的第一项工作任务(在守门员之后):

构建后构建阶段的最后一步(成功或不成功)

还有一个故障保护cron清理任务,可以删除任何超过几个小时的资源网关目录(在本例中为3个)。不应该是必需的,但可以防止构建被无限期地捆绑,以防在没有运行最终任务的情况下重新启动Bambol本身

# 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实现一个永久解决方案之前,它足以让我们绕过这个问题。我希望它能帮助其他人。

“直到Atlassian实施永久解决方案”最近以“未被考虑”的状态关闭。因此,选项是自制,或者不使用竹子。如果/test/atlassian/bambon gatekeeper/inuse-${bambon.gatekeeper.resource}位于共享位置,您不必为此绑定竹子代理?
file=/test/atlassian/bamboo-gatekeeper/inuse-${bamboo.gatekeeper.resource}
rm -rf "$file"
# 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