Bamboo から Bitbucket Pipelines に移行する方法
アトラシアンでは、Bitbucket Cloud の CI/CD (継続的インテグレーションと継続的なデリバリー) 用に、Bitbucket Pipelines (Bitbucket Cloud に組み込み) と Bamboo Data Center の 2 つの主要オプションを提供しています。
If you’re using Bitbucket Cloud to for your code, migrating your CI/CD pipelines to Bitbucket Pipelines will improve your overall CI/CD experience. Since it’s built-in to Bitbucket Cloud, there is no integration to manage or plugins to install. You’ll be able to use Atlassian’s cloud runners to scale on demand (or connect to your own runners), easily extend your workflows using Pipes, and manage your pipelines at scale to meet your compliance needs. Learn more about the benefits of migrating to Bitbucket Pipelines.
Bamboo から Bitbucket Pipelines への移行を検討しているカスタマー向けに、構文の違いに関するガイドと、移行プランに関するガイドラインがあります。
まず、変数の定義方法について説明しましょう。
Variables
Bitbucket Pipelines categorizes variables in the following way:
既定の変数: Pipelines は、ビルドで利用でき、スクリプトでも使用可能な一連の既定の変数を提供します。たとえば、$BITBUCKET_BUILD_NUMBER です。
ワークスペース変数: ワークスペースに指定した変数は、そのワークスペースに所属するすべてのリポジトリからアクセスできます。
リポジトリ変数: リポジトリで書き込みアクセス権限を持つユーザーは、リポジトリ レベルで追加されたパイプライン変数を使用できます。
デプロイ変数: また、特定のデプロイ環境でのみ使用されるように変数を定義することもできます。
It’s also worth mentioning that Bitbucket Pipelines supports OIDC (OpenID Connect) to allow accessing third-party and internal applications securely without storing credentials.
Bamboo categorizes variables based on their scope as follows:
ビルド固有の変数: ビルド時に Bamboo プロパティまたはプラグインから動的に評価されます。たとえば、
${bamboo.planKey}です。デプロイ変数: プロジェクトのデプロイ時に使用できます。
システム変数: Bamboo インスタンス全体に適用し、システム変数または環境変数から値を継承します。
グローバル変数: すべてのプラン機能の静的な値を使用してインスタンス レベルで定義されます。
プロジェクト変数: 特定のプロジェクトに対して定義され、グローバル変数を上書きできます。
プラン機能変数:特定のプラン機能に対して定義され、グローバル変数およびプロジェクト変数を上書きでき、ビルド中に手動で上書きできます。
変数の設定方法にはこのような根本的な違いがあるため、ここでは Bamboo プラン機能を Bitbucket Pipelines に移行する方法の例をいくつか示します。
構文例
以下に、Bamboo から Bitbucket Pipelines への移行に関する例と構文比較を示します。
Hello World ビルドの実行
Bamboo YAML 仕様 | Pipelines |
|---|---|
---
version: 2
plan:
project-key: PROJ
key: PLAN
name: Example Plan
stages:
- Stage 1:
jobs:
- Job 1
Job 1:
tasks:
- script:
- echo 'Hello World' | image: atlassian/default-image:4
pipelines:
default:
- step:
name: Example
script:
- echo 'Hello World' |
並列ジョブの実行
Bamboo YAML 仕様 | Pipelines |
|---|---|
---
version: 2
plan:
project-key: PROJ
key: PLAN
name: Example Plan
stages:
- Stage 1:
jobs:
- Build and Test
- Lint
- Security scan
Build and Test:
tasks:
- script:
- echo "Your build and test goes here..."
Lint:
tasks:
- script:
- echo "Your linting goes here..."
Security scan:
tasks:
- script:
- echo "Your security scan goes here..." | image: atlassian/default-image:4
pipelines:
default:
- parallel:
- step:
name: 'Build and Test'
script:
- echo "Your build and test goes here..."
- step:
name: 'Lint'
script:
- echo "Your linting goes here..."
- step:
name: 'Security scan'
script:
- echo "Your security scan goes here..." |
資格情報の処理
次のパイプライン コードは、シークレット テキストの資格情報に環境変数を使用してパイプラインを作成する方法の例を示しています。
Bamboo YAML 仕様 | Pipelines |
|---|---|
---
version: 2
plan:
project-key: PROJ
key: PLAN
name: Example Plan
stages:
- Stage 1:
jobs:
- Example Job
Example Job:
tasks:
- script:
- echo "Running ${bamboo.buildNumber} on ${bamboo.planRepository.repositoryUrl}" | image: atlassian/default-image:4
pipelines:
default:
- step:
name: Example
script:
- echo "Running $BITBUCKET_BUILD_NUMBER on $BITBUCKET_GIT_HTTP_ORIGIN"
|
タイムアウトの設定
Bamboo YAML 仕様 | Pipelines |
|---|---|
Based on your settings, Bamboo can determine if a build is hanging or timed out. You can override these settings for individual plans in the executable configuration of each plan. Build monitoring is enabled by default. | Pipelines では、パラメーターを設定して各ステップのタイムアウト制限を定義できます。 image: atlassian/default-image:4
pipelines:
default:
- step:
name: Example
script:
- echo 'Hello World'
max-time: 60 # Timeout in minutes |
cron 式
Bamboo YAML 仕様 | Pipelines |
|---|---|
---
version: 2
#short syntax
triggers:
- cron: 0 * * * ? * | Bitbucket Pipelines scheduled builds are configured in the user interface. You can easily set up and manage your build schedules, specify the frequency, and timing of builds. |
ビルド、テスト、デプロイ
Bamboo YAML 仕様 | Pipelines |
|---|---|
---
version: 2
plan:
project-key: PROJ
key: PLAN
name: Example Plan
stages:
- Lint and Test:
- Lint
- Build Artifact:
- Build Artifact
- Publish Image:
- Publish Image
Lint:
tasks:
- script:
- npm install
- npm lint
docker:
image: node:alpine
Build Artifact:
tasks:
- script:
- ${bamboo_capability_system_builder_npm} install
- ${bamboo_capability_system_builder_npm} run build
- script:
- cp -r content build/
- cp release/* build/
requirements:
- node
artifacts:
- name: release
pattern: build/**
Deploy Image:
tasks:
- artifact-download:
source-plan: PROJ-PLAN
artifacts:
- name: release | image: atlassian/default-image:4
pipelines:
default:
- step:
name: Lint and Test
caches:
- node
script:
- npm install
- npm lint
- npm test
- step:
name: Build Artifact
script:
- npm install
- npm run build
- cp -r content build/
- cp release/* build/
- zip -r build.zip build/
artifacts:
- build.zip
- step:
name: Deploy Image
services:
- docker
script:
- pipe: atlassian/aws-code-deploy:1.5.0
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
S3_BUCKET: $S3_BUCKET
COMMAND: "upload"
APPLICATION_NAME: "my-application"
ZIP_FILE: "build.zip" |
移行のベスト プラクティス
Bamboo から Bitbucket Pipelines への移行には、段階的な移行アプローチを推奨します。この戦略では、必要に応じて Bamboo を活用しながら、既存のリポジトリを Bitbucket Pipelines に徐々に移行できるため、スムーズで効率的な移行を確実に行うことができます。
You can start by migrating less critical repositories or parts of your build processes to Bitbucket Pipelines, testing and refine your configurations along the way. During this transitional period, you can configure Bitbucket Pipelines to trigger Bamboo jobs using the bamboo-trigger-build pipe. This hybrid approach enables you to gradually familiarize your team with Bitbucket Pipelines and address any migration challenges without disrupting your ongoing development processes.
ここでは、Pipelines から基本的な Bamboo ジョブをトリガーする方法の例をいくつか示します。
script:
- pipe: atlassian/bamboo-trigger-build:0.6.0
variables:
BAMBOO_ENDPOINT: 'http://your-bamboo.net:8085'
PROJECT_KEYWORD: 'TEST'
PLAN_KEYWORD: 'TEST'
TOKEN: '<your access token>'Bamboo ジョブのビルドをトリガーし、ビルドが完了するまで待ちます。
ワークフローには十分なWAIT時間を設定してください。
script:
- pipe: atlassian/bamboo-trigger-build:0.6.0
variables:
BAMBOO_ENDPOINT: 'http://your-bamboo.net:8085'
PROJECT_KEYWORD: 'TEST'
PLAN_KEYWORD: 'TEST'
TOKEN: '<your access token>'
WAIT: 'true'
WAIT_INTERVAL: '15'
この内容はお役に立ちましたか?