Skip to main content

使用 GitHub Actions Importer 从 Bamboo 迁移

了解如何使用 GitHub Actions Importer 自动将 Bamboo 管道迁移到 GitHub Actions。

法律通告

关于使用 GitHub Actions Importer 从 Bamboo 迁移

以下说明将指导你配置环境,以使用 GitHub Actions Importer 将 Bamboo 管道迁移到 GitHub Actions。

先决条件

  • 具有要转换为 GitHub Actions 工作流的项目和管道的 Bamboo 帐户或组织。

  • Bamboo 版本 7.1.1 或更高版本。

  • 具备为帐户或组织创建 Bamboo personal access token 的权限。

  • 一个可在其中运行基于 Linux 的容器并可安装所需工具的环境。

    注意:GitHub Actions Importer 容器和 CLI 不需要安装在 CI 平台所在的同一服务器上。

限制

使用 GitHub Actions Importer 从 Bamboo 迁移到 GitHub Actions 时,存在一些限制:

  • GitHub Actions Importer 依赖于 Bamboo 服务器生成的 YAML 规范来执行迁移。 如果 Bamboo 不支持将某些内容导出到 YAML,则不会迁移缺少的信息。
  • 不支持触发器条件。 当 GitHub Actions Importer 遇到具有条件的触发器时,该条件将显示为注释,并且触发器在没有该注释的情况下进行转换。
  • 不会转换具有用于存储项目的自定义设置的 Bamboo 计划, 而是使用 upload-artifactdownload-artifact 操作存储和检索项目。
  • 必须在 GitHub UI 中手动禁用已禁用的计划。 有关详细信息,请参阅“禁用和启用工作流”。
  • 禁用的作业使用阻止其运行的 if: false 条件进行转换。 必须删除此项才能重新启用作业。
  • 禁用的任务不会转换,因为它们在使用 Bamboo API 时未包含在导出的计划中。
  • Bamboo 提供了在生成完成后清理生成工作区的选项。 这些选项不会转换,因为假定 GitHub 托管的运行器或临时自托管运行器将自动处理此问题。
  • 不会转换挂起生成检测选项,因为 GitHub Actions 中没有等效项。 最接近的选项位于作业的 timeout-minutes 上,可用于设置允许作业运行的最大分钟数。 有关详细信息,请参阅“GitHub Actions 的工作流语法”。
  • 模式匹配标记不会转换,因为 GitHub Actions 中没有等效项。
  • 所有项目都将转换为 actions/upload-artifact,无论其是否是 shared,因此可以从工作流中的任何作业下载这些项目。
  • 权限不会转换,因为 GitHub Actions 中没有合适的等效项。
  • 如果 Bamboo 版本在 7.1.1 和 8.1.1 之间,则不会迁移项目和计划变量。

手动任务

某些 Bamboo 构造必须手动迁移。 其中包括:

  • 掩码变量
  • 项目过期设置

安装 GitHub Actions Importer CLI 扩展

  1. 安装 GitHub Actions Importer CLI 扩展:

    Bash
    gh extension install github/gh-actions-importer
    
  2. 验证是否已安装扩展:

    $ gh actions-importer -h
    Options:
      -?, -h, --help  Show help and usage information
    
    Commands:
      update     Update to the latest version of GitHub Actions Importer.
      version    Display the version of GitHub Actions Importer.
      configure  Start an interactive prompt to configure credentials used to authenticate with your CI server(s).
      audit      Plan your CI/CD migration by analyzing your current CI/CD footprint.
      forecast   Forecast GitHub Actions usage from historical pipeline utilization.
      dry-run    Convert a pipeline to a GitHub Actions workflow and output its yaml file.
      migrate    Convert a pipeline to a GitHub Actions workflow and open a pull request with the changes.
    

配置凭据

configure CLI 命令用于在使用 Bamboo 和 GitHub 时为 GitHub Actions Importer 设置所需的凭据和选项。

  1. 创建 GitHub personal access token (classic)。 有关详细信息,请参阅“管理个人访问令牌”。

    令牌必须具有 workflow 范围。

    创建令牌后,将其复制并保存在安全的位置供之后使用。

  2. 创建 Bamboo personal access token。 有关详细信息,请参阅 Bamboo 文档中的 Personal Access Tokens

    令牌必须具有以下权限,具体取决于要转换的资源。

    资源类型查看查看配置编辑
    生成计划
    部署项目
    部署环境

    创建令牌后,将其复制并保存在安全的位置供之后使用。

  3. 在终端中,运行 GitHub Actions Importer configure CLI 命令:

    gh actions-importer configure
    

    configure 命令将提示你输入以下信息:

    • 对于“正在配置哪些 CI 提供程序?”,请使用箭头键选择 Bamboo,按空格键将其选中,然后按 Enter
    • 对于“Personal access token for GitHub”,输入前面创建的 personal access token (classic) 的值,然后按 Enter
    • 对于“GitHub 实例的基 URL”,按 Enter 以接受默认值 (https://github.com)。
    • 对于“Bamboo Personal access token”,请输入前面创建的 Bamboo personal access token 的值,然后按 Enter
    • 对于“Bamboo 实例的基 URL”,输入 Bamboo服务器或 Bamboo 数据中心实例的 URL,然后按 Enter

    configure 命令的示例如下所示:

    $ gh actions-importer configure
    ✔ Which CI providers are you configuring?: Bamboo
    Enter the following values (leave empty to omit):
    ✔ Personal access token for GitHub: ***************
    ✔ Base url of the GitHub instance: https://github.com
    ✔ Personal access token for Bamboo: ********************
    ✔ Base url of the Bamboo instance: https://bamboo.example.com
    Environment variables successfully updated.
    
  4. 在终端中,运行 GitHub Actions Importer update CLI 命令以连接到 GitHub Packages Container registry,并确保容器映像已更新到最新版本:

    gh actions-importer update
    

    命令的输出应类似于以下内容:

    Updating ghcr.io/actions-importer/cli:latest...
    ghcr.io/actions-importer/cli:latest up-to-date
    

对 Bamboo 执行审核

可以使用 audit 命令获取 Bamboo 组织中所有项目的概要视图。

audit 命令执行以下步骤:

  1. 提取 Bamboo 组织中定义的所有项目。
  2. 将每个管道转换为其等效的 GitHub Actions 工作流。
  3. 生成一个报告,汇总使用 GitHub Actions Importer 进行迁移的完成程度和复杂性。

运行审核命令

若要对 Bamboo 实例执行审核,请在终端中运行以下命令:

gh actions-importer audit bamboo --output-dir tmp/audit

检查审核结果

指定的输出目录中的文件包含审核结果。 有关审核结果的摘要,请参阅 audit_summary.md 文件。

审核摘要包含以下部分。

管道

“管道”部分包含有关由 GitHub Actions Importer 完成的转换率的概要统计信息。

下面列出了“管道”部分中可能出现的一些关键术语:

  • “成功”管道已将所有管道构造和单个项目自动转换为其 GitHub Actions 等效项。
  • “部分成功”管道已转换所有管道构造,但有一些单个项目未自动转换为其 GitHub Actions 等效项。
  • “不受支持”管道是 GitHub Actions Importer 不支持的定义类型。
  • “失败”管道在转换时遇到错误。 这可能是以下三个原因之一造成的:
    • 管道配置错误,在 Bamboo 中无效。
    • GitHub Actions Importer 在转换它时遇到内部错误。
    • 网络响应失败,导致管道无法访问,这通常是由于凭据无效所致。

生成步骤

“生成步骤”部分概述了跨所有管道使用的各个生成步骤,以及由 GitHub Actions Importer 自动转换的生成步骤数。

下面列出了“生成步骤”部分中可能出现的一些关键术语:

  • “已知”生成步骤是自动转换为等效操作的步骤。
  • “未知”生成步骤是未自动转换为等效操作的步骤。
  • “不受支持”生成步骤是满足以下任一条件的步骤:
    • 从根本上不受 GitHub Actions 支持。
    • 以与 GitHub Actions 不兼容的方式进行配置。
  • “操作”是转换后的工作流中使用的操作的列表。 这对于以下情况可能很重要:
    • 如果使用 GitHub Enterprise Server,收集要同步到实例的操作列表。
    • 定义所使用的操作的组织级允许列表。 此操作列表是安全或合规性团队可能需要审查的操作的综合列表。

手动任务

“手动任务”部分概述了 GitHub Actions Importer 无法自动完成且必须由你手动完成的任务。

下面列出了“手动任务”部分中可能出现的一些关键术语:

  • “机密”是在转换后的管道中使用的存储库或组织级机密。 必须在 GitHub Actions 中手动创建这些机密,才能使这些管道正常运行。 有关详细信息,请参阅“在 GitHub Actions 中使用机密”。
  • “自托管运行器”是指在转换后的管道中引用的运行器(不是 GitHub 托管的运行器)的标签。 需要手动定义这些运行器,才能使这些管道正常运行。

文件

审核报告的最后一部分提供审核期间写入磁盘的所有文件的清单。

每个管道文件都包含审核中的各种文件,包括:

  • GitHub 中定义的原始管道。
  • 用于转换管道的任何网络响应。
  • 转换后的工作流文件。
  • 可用于排查管道转换失败问题的堆栈跟踪。

此外,workflow_usage.csv 文件包含一个以逗号分隔的列表,其中列出了每个成功转换的管道所使用的所有操作、机密和运行器。 这有助于确定哪些工作流使用哪些操作、机密或运行器,并且可用于进行安全评审。

预测使用情况

可以使用 forecast 命令通过计算 Bamboo 实例中已完成管道运行的指标来预测可能的 GitHub Actions 使用情况。

运行预测命令

若要预测可能的 GitHub Actions 使用情况,请在终端中运行以下命令。 默认情况下,GitHub Actions Importer 在预测报告中包括过去七天的信息。

gh actions-importer forecast bamboo --output-dir tmp/forecast_reports

预测项目

若要将预测限制为与项目关联的计划和部署环境,可以使用 --project 选项,其中值设置为生成项目密钥。

例如:

gh actions-importer forecast bamboo --project PAN --output-dir tmp/forecast_reports

检查预测报告

指定的输出目录中的 forecast_report.md 文件包含预测结果。

下面列出了预测报告中可能出现的一些关键术语:

  • “作业计数”是已完成作业的总数。
  • “管道计数”是使用的独立管道数。
  • “执行时间”指的是运行器在一项作业中所用的时间。 此指标可用于帮助计划 GitHub 托管的运行器的成本。
    • 此指标与你应在 GitHub Actions 中花费的成本相关。 这会因这些分钟所使用的硬件而异。 可以使用 GitHub Actions 定价计算器来估算成本。
  • “队列时间”指标用于描述等待运行器可用于执行作业的时间。
  • “并发作业”指标用于描述在任何给定时间运行的作业数量。 此指标可用于

执行 Bamboo 管道的试运行迁移

可以使用 dry-run 命令将 Bamboo 管道转换为等效的 GitHub Actions 工作流。 试运行在指定目录中创建输出文件,但不打开拉取请求来迁移管道。

为生成计划运行试运行迁移

若要执行将 Bamboo 生成计划迁移到 GitHub Actions 的试运行,请在终端中运行以下命令,将 :my_plan_slug 替换为计划的项目和 <projectKey>-<planKey> 格式的计划密钥(例如:PAN-SCRIP)。

gh actions-importer dry-run bamboo build --plan-slug :my_plan_slug --output-dir tmp/dry-run

为部署项目运行试运行迁移

若要执行将 Bamboo 部署项目发布管道迁移到 GitHub Actions 的试运行,请在终端中运行以下命令,将 :my_deployment_project_id 替换为要转换的部署项目的 ID。

gh actions-importer dry-run bamboo deployment --deployment-project-id :my_deployment_project_id --output-dir tmp/dry-run

可以在指定的输出目录中查看试运行日志和转换后的工作流文件。

如果有任何 GitHub Actions Importer 无法自动转换的内容,例如未知生成步骤或部分成功管道,你可能需要创建自定义转换器来进一步自定义转换过程。 有关详细信息,请参阅“使用自定义转换器扩展 GitHub Actions 导入工具”。

执行 Bamboo 管道的生产迁移

可以使用 migrate 命令转换 Bamboo 管道,并使用等效的 GitHub Actions 工作流打开拉取请求。

为生成计划运行 migrate 命令

若要将 Bamboo 生成计划迁移到 GitHub Actions,请在终端中运行以下命令,将 target-url 值替换为 GitHub 存储库的 URL,并将 :my_plan_slug 替换为计划的项目和 <projectKey>-<planKey> 格式的计划密钥。

gh actions-importer migrate bamboo build --plan-slug :my_plan_slug --target-url :target_url --output-dir tmp/migrate

命令的输出包括将转换后的工作流添加到存储库的拉取请求的 URL。 成功输出的示例类似于以下内容:

$ gh actions-importer migrate bamboo build --plan-slug :PROJECTKEY-PLANKEY --target-url https://github.com/octo-org/octo-repo --output-dir tmp/migrate
[2022-08-20 22:08:20] Logs: 'tmp/migrate/log/actions-importer-20220916-014033.log'
[2022-08-20 22:08:20] Pull request: 'https://github.com/octo-org/octo-repo/pull/1'

为部署项目运行 migrate 命令

若要将 Bamboo 部署管道迁移到 GitHub Actions,请在终端中运行以下命令,将 target-url 值替换为 GitHub 存储库的 URL,并将 :my_deployment_project_id 替换为要转换的部署项目的 ID。

gh actions-importer migrate bamboo deployment --deployment-project-id :my_deployment_project_id --target-url :target_url --output-dir tmp/migrate

命令的输出包括将转换后的工作流添加到存储库的拉取请求的 URL。 成功输出的示例类似于以下内容:

$ gh actions-importer migrate bamboo deployment --deployment-project-id 123 --target-url https://github.com/octo-org/octo-repo --output-dir tmp/migrate
[2023-04-20 22:08:20] Logs: 'tmp/migrate/log/actions-importer-20230420-014033.log'
[2023-04-20 22:08:20] Pull request: 'https://github.com/octo-org/octo-repo/pull/1'

检查拉取请求

migrate 命令成功运行的输出包含一个指向新拉取请求的链接,此拉取请求将转换后的工作流添加到存储库。

拉取请求的一些重要元素包括:

  • 在拉取请求说明中,有一个名为“手动步骤”的部分,其中列出了在完成将管道迁移到 GitHub Actions 之前必须手动完成的步骤。 例如,此部分可能会提供创建工作流中使用的任何机密。
  • 转换后的工作流文件。 选择拉取请求中的“已更改的文件”选项卡,查看将添加到 GitHub Enterprise Cloud 存储库的工作流文件。

检查完拉取请求后,可以将其合并以将工作流添加到 GitHub Enterprise Cloud 存储库。

参考

本部分包含使用 GitHub Actions Importer 从 Bamboo 迁移时涉及的环境变量、可选参数和支持的语法的参考信息。

使用环境变量

GitHub Actions Importer 使用环境变量进行身份验证配置。 这些变量在使用 configure 命令执行配置过程时设置。 有关详细信息,请参阅“配置凭据”部分。

GitHub Actions Importer 使用以下环境变量连接到 Bamboo 实例:

  • GITHUB_ACCESS_TOKEN:用于通过转换后的工作流创建拉取请求的 personal access token (classic)(需要 repoworkflow 范围)。
  • GITHUB_INSTANCE_URL:目标 GitHub 实例的 URL(例如 https://github.com)。
  • BAMBOO_ACCESS_TOKEN:用于向 Bamboo 实例进行身份验证的 Bamboo personal access token。
  • BAMBOO_INSTANCE_URL:Bamboo 实例的 URL(例如 https://bamboo.example.com)。

这些环境变量可以在 GitHub Actions Importer 运行时加载的 .env.local 文件中指定。

可选自变量

有一些可选参数可以结合 GitHub Actions Importer 子命令使用来自定义迁移。

--source-file-path

可以将 --source-file-path 参数与 dry-runmigrate 子命令结合使用。

默认情况下,GitHub Actions Importer 从 Bamboo 实例中提取管道内容。 --source-file-path 参数指示 GitHub Actions Importer 改用指定的源文件路径。

例如:

gh actions-importer dry-run bamboo build --plan-slug IN-COM -o tmp/bamboo --source-file-path ./path/to/my/bamboo/file.yml

--config-file-path

可以将 --config-file-path 参数与 auditdry-runmigrate 子命令结合使用。

默认情况下,GitHub Actions Importer 从 Bamboo 实例中提取管道内容。 --config-file-path 参数指示 GitHub Actions Importer 改用指定的源文件。

“审核”示例

在此示例中,GitHub Actions Importer 使用指定的 YAML 配置文件来执行审核。

gh actions-importer audit bamboo -o tmp/bamboo --config-file-path "./path/to/my/bamboo/config.yml"

若要使用配置文件审核 Bamboo 实例,配置文件必须采用以下格式,并且每个 repository_slug 都必须是唯一的:

source_files:
  - repository_slug: IN/COM
    path: path/to/one/source/file.yml
  - repository_slug: IN/JOB
    path: path/to/another/source/file.yml
试运行示例

在此示例中,GitHub Actions Importer 使用指定的 YAML 配置文件作为源文件来执行试运行。

存储库 slug 是使用 --plan-slug 选项生成的。 源文件路径是匹配的,并从指定的源文件中拉取。

gh actions-importer dry-run bamboo build --plan-slug IN-COM -o tmp/bamboo --config-file-path "./path/to/my/bamboo/config.yml"

Bamboo 管道支持的语法

下表显示了 GitHub Actions Importer 当前能够转换的属性类型。

BambooGitHub 操作状态
environmentsjobs支持
environments.<environment_id>jobs.<job_id>受支持
<job_id>.artifactsjobs.<job_id>.steps.actions/upload-artifact受支持
<job_id>.artifact-subscriptionsjobs.<job_id>.steps.actions/download-artifact受支持
<job_id>.dockerjobs.<job_id>.container受支持
<job_id>.final-tasksjobs.<job_id>.steps.if受支持
<job_id>.requirementsjobs.<job_id>.runs-on受支持
<job_id>.tasksjobs.<job_id>.steps受支持
<job_id>.variablesjobs.<job_id>.env受支持
stagesjobs.<job_id>.needs受支持
stages.<stage_id>.finaljobs.<job_id>.if受支持
stages.<stage_id>.jobsjobs受支持
stages.<stage_id>.jobs.<job_id>jobs.<job_id>受支持
stages.<stage_id>.manualjobs.<job_id>.environment受支持
triggerson支持
dependenciesjobs.<job_id>.steps.<gh cli step>部分支持
branches不适用不支持
deployment.deployment-permissions不适用不支持
environment-permissions不适用不支持
notifications不适用不支持
plan-permissions不适用不支持
release-naming不适用不支持
repositories不适用不支持

有关支持的 Bamboo 概念和插件映射的详细信息,请参阅 github/gh-actions-importer 存储库

环境变量映射

GitHub Actions Importer 使用下表中的映射将默认 Bamboo 环境变量转换为 GitHub Actions 中最接近的等效项。

BambooGitHub 操作
bamboo.agentId${{ github.runner_name }}
bamboo.agentWorkingDirectory${{ github.workspace }}
bamboo.buildKey${{ github.workflow }}-${{ github.job }}
bamboo.buildNumber${{ github.run_id }}
bamboo.buildPlanName${{ github.repository }}-${{ github.workflow }}-${{ github.job }
bamboo.buildResultKey${{ github.workflow }}-${{ github.job }}-${{ github.run_id }}
bamboo.buildResultsUrl${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
bamboo.build.working.directory${{ github.workspace }}
bamboo.deploy.project${{ github.repository }}
bamboo.ManualBuildTriggerReason.userName${{ github.actor }}
bamboo.planKey${{ github.workflow }}
bamboo.planName${{ github.repository }}-${{ github.workflow }}
bamboo.planRepository.branchDisplayName${{ github.ref }}
bamboo.planRepository.<position>.branch${{ github.ref }}
bamboo.planRepository.<position>.branchName${{ github.ref }}
bamboo.planRepository.<position>.name${{ github.repository }}
bamboo.planRepository.<position>.repositoryUrl${{ github.server }}/${{ github.repository }}
bamboo.planRepository.<position>.revision${{ github.sha }}
bamboo.planRepository.<position>.username${{ github.actor}}
bamboo.repository.branch.name${{ github.ref }}
bamboo.repository.git.branch${{ github.ref }}
bamboo.repository.git.repositoryUrl${{ github.server }}/${{ github.repository }}
bamboo.repository.pr.key${{ github.event.pull_request.number }}
bamboo.repository.pr.sourceBranch${{ github.event.pull_request.head.ref }}
bamboo.repository.pr.targetBranch${{ github.event.pull_request.base.ref }}
bamboo.resultsUrl${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
bamboo.shortJobKey${{ github.job }}
bamboo.shortJobName${{ github.job }}
bamboo.shortPlanKey${{ github.workflow }}
bamboo.shortPlanName${{ github.workflow }}

注意:未知变量将转换为 ${{ env.<variableName> }},并且必须在 env 下进行替换或添加变量才能正常操作。 例如,${bamboo.jira.baseUrl} 将变为 ${{ env.jira_baseUrl }}

系统变量

任务中使用的系统变量将转换为等效的 bash shell 变量,并假定可用。 例如,${system.<variable.name>} 将转换为 $variable_name。 建议对此进行验证,以确保工作流正常运行。

部分内容改编自 MIT 许可证下的 https://github.com/github/gh-actions-importer/

MIT License

Copyright (c) 2022 GitHub

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.