Atlassian Bamboo 集成
当您将更改推送到极狐GitLab 中的项目时,您可以在 Atlassian Bamboo 中自动触发构建。
在接受 Webhook 和提交数据时,Bamboo 不提供与传统构建系统相同的功能。在极狐GitLab 中配置集成之前,您必须配置 Bamboo 构建计划。
配置 Bamboo
- 在 Bamboo 中,转到构建计划并选择 Actions > Configure plan。
- 选择 Triggers 选项卡。
- 选择 Add trigger。
- 输入类似“极狐GitLab 触发器”的描述。
- 选择 Repository triggers the build when changes are committed。
- 选中一个或多个仓库的复选框。
- 在 Trigger IP addresses 中输入极狐GitLab IP地址。允许这些 IP 地址触发 Bamboo 构建。
- 保存触发器。
- 在左侧窗格中,选择构建阶段。如果您有多个构建阶段,请选择包含 Git 检出任务的最后一个阶段。
- 选择 Miscellaneous 选项卡。
- 在 Pattern Match Labeling 下,在 Labels 中输入
${bamboo.repository.revision.number}
。 - 选择 Save。
Bamboo 已准备好接受来自极狐GitLab 的触发。接下来,在极狐GitLab 中设置 Bamboo 集成。
配置极狐GitLab
- 在左侧边栏中,选择 搜索或转到 并找到您的项目。
- 在左侧边栏中,选择 设置 > 集成。
- 选择 Atlassian Bamboo。
- 确保选中 启用 复选框。
- 输入您的 Bamboo 服务器的基本 URL。例如,
https://bamboo.example.com
。 - 可选。清除 启用 SSL 验证 复选框,禁用 SSL 验证。
- 输入 Bamboo 构建计划中的构建密钥。
- 如有必要,输入有权触发构建计划的 Bamboo 用户的用户名和密码。如果您不需要身份验证,请将这些字段留空。
- 可选。要在 Bamboo 中测试配置并触发构建,请选择 测试设置。
- 选择 保存修改。
确定 Bamboo 构建计划构建密钥
构建密钥是通常由项目密钥和计划密钥组成的唯一标识符。
构建密钥很短,全部大写,并用破折号 (-
) 分隔,例如 PROJ-PLAN
。
当您在 Bamboo 中查看计划时,构建密钥包含在浏览器 URL 中。例如,https://bamboo.example.com/browse/PROJ-PLAN
。
在极狐GitLab 中更新 Bamboo 构建状态
您可以使用一个使用提交状态 API和 Bamboo 构建变量的脚本来:
- 更新提交的构建状态。
- 将 Bamboo 构建计划 URL 添加为提交的
target_url
。
比如:
- 在极狐GitLab 中创建一个具有
:api
权限的访问令牌。 - 将令牌保存为 Bamboo 中的
$GITLAB_TOKEN
变量。 -
将以下脚本添加为 Bamboo 计划作业的最终内联脚本任务:
#!/bin/bash # Script to update CI status on GitLab. # Add this script as final inline script task in a Bamboo job. # # General documentation: https://docs.gitlab.com/ee/user/project/integrations/bamboo.html # Fix inspired from https://gitlab.com/gitlab-org/gitlab/-/issues/34744 # Stop at first error set -e # Access token. Set this as a CI variable in Bamboo. #GITLAB_TOKEN= # Status cistatus="failed" if [ "${bamboo_buildFailed}" = "false" ]; then cistatus="success" fi repo_url="${bamboo_planRepository_repositoryUrl}" # Check if we use SSH or HTTPS protocol=${repo_url::4} if [ "$protocol" == "git@" ]; then repo=${repo_url:${#protocol}}; gitlab_url=${repo%%:*}; else protocol="https://" repo=${repo_url:${#protocol}}; gitlab_url=${repo%%/*}; fi start=$((${#gitlab_url} + 1)) # +1 for the / (https) or : (ssh) end=$((${#repo} - $start -4)) # -4 for the .git repo=${repo:$start:$end} repo=$(echo "$repo" | sed "s/\//%2F/g") # Send request url="https://${gitlab_url}/api/v4/projects/${repo}/statuses/${bamboo_planRepository_revision}?state=${cistatus}&target_url=${bamboo_buildResultsUrl}" echo "Sending request to $url" curl --fail --request POST --header "PRIVATE-TOKEN: $GITLAB_TOKEN" "$url"
故障排除
构建未触发
如果未触发构建,请确保您在 Bamboo 中的 Trigger IP addresses 下输入了正确的极狐GitLab IP 地址。还要检查服务钩子日志是否有请求失败。
高级 Atlassian Bamboo 功能在极狐GitLab UI 中不可用
高级 Atlassian Bamboo 功能与极狐GitLab 不兼容。这些功能包括但不限于从极狐GitLab UI 查看构建日志的能力。