Bamboo 変数
Variables can be used to make values available when building plans in Bamboo.
- ビルド固有の変数は、ビルド時に Bamboo によって動的に評価されます。ビルド固有の変数のソースは、Bamboo プロパティでも既定のプラグインのいずれかでもかまいません (有効になっている場合)。
- デプロイ変数は、プロジェクトのデプロイ時に使用できます。
- システム変数は Bamboo インスタンス全体にも適用され、同じ名前のシステム変数または環境変数から値を継承します。
- グローバル変数は Bamboo インスタンス全体で定義され、Bamboo によってビルドされたすべての計画で同じ (静的な) 値を持ちます。「グローバル変数を定義する」をご参照ください。
- Project variables are defined for specific projects. Project variables can override global variables with the same name. See Defining project variables.
- Plan variables are similar to global variables, but are defined for specific plans. Plan variables override global and project variables with the same name. You can also override a plan variable for a build if you trigger the build manually. See Defining plan variables.
変数を利用する
Variables can be used in all fields of a task or deployment, with the exception of password fields. Use the following format when referencing a variable:
${bamboo.variableName}
ビルドを手動でトリガーすれば、ビルドのプラン変数を上書きできます。「計画ビルドを手動でトリガーする」をご参照ください。
You can reference a variable from another variables, e.g. consider having the following variables:
var1 = Hello
var2 = world
You can create another variable which references the two other one.
${bamboo.var1} ${bamboo.var2}!
Bamboo will resolve the variable as Hello World!
以下のことが可能です。
- reference a global or context specific variable in a build plan or deployment project
- reference a variable which references another one, deep recursion is allowed
There are couple of limitations:
- referencing a variable which isn't defined is an error, whole build or deployment will fail if you reference such variable
- cycles are not allowed and are considered as build or deployment project error.
カスタム変数を定義する
上記と同様の形式を使用して独自のカスタム変数を定義できます。ただし、Bamboo ですでに使用されている変数名を作成することはできません。
Bamboo で独自の変数を定義する方法については、次の内容をご参照ください。
このページの内容
ビルド固有の変数
次のビルド固有の変数が初期設定で用意されています。
- System variables apply across your entire Bamboo instance and inherit their values from system or environment variables of the same name.
- In the variable names from the table, <position> is an optional parameter that specifies the position of the repository in the plan's repository list. If omitted, the first repository in the list is used.
- Third-party repository plugins can expose their own variables.
ビルド固有の変数 | 説明 |
---|---|
bamboo.buildKey | 現在のジョブのジョブ キー、"プロジェクト - 計画 - ジョブ" の形式、例: |
bamboo.planKey | 現在の計画のキー、"プロジェクト - 計画" の形式、例: BAM-MAIN |
bamboo.shortPlanKey | 現在の計画の短いキー (プロジェクト部分なし)、例: MAIN |
bamboo.shortJobKey | 現在のジョブの短いキー (プロジェクトと計画の部分なし)、例: JOBX |
bamboo.buildResultKey | このジョブの実行時の結果キー、"プロジェクト - 計画 - ジョブ - ビルド" の形式、例: BAM-BOO-JOB1-8 ("8" はビルド番号)、デプロイ プロジェクトではこの変数にジョブ部分が含まれない (例: PROJ-TP-6 ) |
bamboo.buildResultsUrl または bamboo.resultsUrl | ジョブの実行終了後の Bamboo 内での結果 URL |
bamboo.buildNumber | Bamboo のビルド番号、例: |
bamboo.buildPlanName | Bamboo のジョブ名、例: |
bamboo.planName | 現在の計画の名前、例: Some project name - Some plan name |
bamboo.shortPlanName | 現在の計画の名前 (プロジェクトの部分なし)、例: Some plan name |
bamboo.shortJobName | 現在のジョブの名前 (プロジェクトと計画の部分なし)、例: Some job name |
bamboo.buildTimeStamp | The time when a job was started in ISO 8601 format (for example, 2010-01-01T01:00:00.000+01:00 ) |
bamboo.agentId | デプロイメントが実行されるエージェントの ID |
bamboo.agentWorkingDirectory | The path to the working directory on the agent, for example The agent working directory is not the same as the build working directory described below. |
bamboo.build.working.directory | The working directory on which the build is being executed, for example |
bamboo.ManualBuildTriggerReason.userName | 手動ビルドをトリガーしたユーザー |
一般的なリポジトリ変数 | |
bamboo.planRepository.<position>.branchName | リポジトリ内のブランチの名前 (使用された VCS の可用性による)、例: default |
bamboo.planRepository.<position>.name | 計画のリポジトリに表示されているリポジトリの名前、例: Mercurial |
bamboo.planRepository.<position>.revision | The revision use to build this release. Format depends on the VCS used. |
bamboo.planRepository.<position>.previousRevision | 前のリビジョン番号 (初期ビルドなど、存在しない場合がある) |
bamboo.planRepository.<position>.type | リポジトリのタイプ、リポジトリ プラグインで定義されているとおり、例: hg、svn、git |
bamboo.repository.pr.key | Pull request key if plan branch was created from pull request |
bamboo.repository.pr.sourceBranch | Pull request source branch name if plan branch was created from pull request |
bamboo.repository.pr.targetBranch | Pull request destination branch name if plan branch was created from pull request |
bamboo.planRepository.branchDisplayName | The name of the branch displayed in the branch details section. |
Subversion | |
bamboo.planRepository.<position>.username | リポジトリ認証に使用されるユーザー名 |
bamboo.planRepository.<position>.repositoryUrl | The repository URL. |
CVS | |
bamboo.planRepository.<position>.last.update.time | 最終更新日のタイムスタンプ |
bamboo.planRepository.<position>.last.update.time.label | The last updated timestamp to be used as a label for post build result labeling. The spaces in the cvs version string are replaced with '_'. |
perforce | |
bamboo.planRepository.<position>.revision.number | 変更セット番号 |
bamboo.planRepository.<position>.username | リポジトリ認証に使用されるユーザー名 |
bamboo.planRepository.<position>.port | リポジトリ通信に使用されるポート |
bamboo.planRepository.<position>.client | リポジトリ通信に使用されるクライアント |
Git | |
bamboo.planRepository.<position>.branch | ブランチ |
bamboo.planRepository.<position>.repositoryUrl | The repository URL |
Mercurial | |
bamboo.planRepository.<position>.repositoryUrl | The repository URL |
bamboo.planRepository.<position>.branch | ブランチ |
bamboo.planRepository.<position>.username | リポジトリ認証に使用されるユーザー名 |
- システム変数は Bamboo インスタンス全体にも適用され、同じ名前のシステム変数または環境変数から値を継承します。
- 上記の表の変数名で、<position> は計画のリポジトリ リストにおけるリポジトリの位置を指定するオプションのパラメーターです。省略すると、リストの最初のリポジトリが使用されます。
- Third-party repository plugins can expose their own variables.
ビルド依存関係の変数
次のビルド依存関係の変数も使用できます。
ビルド固有の変数 | 説明 |
---|---|
bamboo.dependency.parent.# | トリガーとなる親ビルドのビルド キーを子ビルドがクエリできるようにします。この場合、# はビルド ツリー内の位置 (0 は最上部、1 はその次など) を表します。${bamboo.dependency.parent.0} 変数は、子計画のメタデータ タブで確認できます。 |
bamboo.dependency.parent.total | 親ビルドの総数 |
デプロイ変数
プロジェクトのデプロイ時に使用できる、複数の標準予約済み変数が Bamboo によって管理されています。
名前が繰り返される場合、次のリストで後にある変数が前の変数をオーバーライドします。
- グローバル変数
- project variables of the plan linked to the deployment project
- plan variables of the plan linked to the deployment project
- 以下に定義されているリリース変数
- 環境レベルで定義されたユーザー変数
- 次の表の自動生成変数
変数 | 説明 |
---|---|
bamboo.agentId | The id of the agent that the deployment is executed on. |
bamboo.agentWorkingDirectory | エージェントの作業ディレクトリへのパス。これは Bamboo の作業ディレクトリとは異なります。 |
bamboo.build.working.directory | Bamboo の作業ディレクトリへのパスです。これはビルド計画とデプロイ プロジェクトの両方で使用されます。 |
bamboo.deploy.environment | リリースがデプロイされる環境の名前。 |
bamboo.deploy.project | デプロイ プロジェクトの名前。 |
bamboo.deploy.rollback | デプロイされるリリースが置き換えられるリリースよりも古い場合に当てはまります。 |
bamboo.deploy.release bamboo.deploy.version | デプロイされているリリースの名前。「.release」と「.version」のいずれかを使用できます。どちらもデプロイされるリリースの名前を返します。 |
bamboo.deploy.release.previous bamboo.deploy.version.previous | 置き換えられるリリースの名前 (利用できる場合)。.release と.version のいずれかを使用できます。どちらも置き換えられるリリースの名前を返します。 |
bamboo.resultsUrl | The URL to the screen in Bamboo that displays build results. |
類似の形式で独自の変数を生成することはできますが、Bamboo ですでに使用されている変数は作成できません。詳細は「デプロイ環境変数を定義する」をご参照ください。
変数をリリースする
Bamboo では、デプロイ リリースに変数の次のタイプを使用できるようにしています。
- Snapshots of values of global variables.
- Snapshots of values of project variables.
- Snapshots of values of plan variables.
- Snapshots of values of repository variables.
- 次の表に記載されている自動生成リリース変数
変数 | 説明 |
---|---|
bamboo.buildNumber | The build result from which the release is created. |
bamboo.buildResultKey | The key of the build result from which the release is created e.g. KUNG-FOO-35 |
bamboo.planKey | リリースに関連する計画のキー、例: KUNG-FOO |
bamboo.planName | リリースに関連する計画の名前、例: Kung - Foo |
bamboo.shortPlanKey | リリースに関連する計画の短いキー (プロジェクト部分なし)、例: MAIN |
bamboo.shortPlanName | 計画の名前 (プロジェクトの部分なし)、例: Some plan name |
Note that several of the variables in the above table are actually those associated with the build plan. The snapshots mentioned above do not contain password variables.
System variables
すべてのシステム変数に使用される形式は次のとおりです。
${system.<variable>}
たとえば、システム変数 MYPATH=C:\MyPath;
がある場合、システム変数と同じ値を継承する Bamboo システム変数 system.MYPATH
を使用できます。
In older Bamboo versions using PATH in the Environment Variables field (of a Script task) doesn't set the windows PATH variable, whereas using Path sets Path and PATH in cmd shell.
bash で変数を使用する
Bamboo 変数は bash シェル変数としてエクスポートされます。すべてのフル ストップ (ピリオド) はアンダースコアに変換されます。たとえば、変数 bamboo.my.variable
は、bash では $bamboo_my_variable
になります。これはファイル スクリプト タスクに関連しています (インライン スクリプト タスクではありません)。
Jira applications variables
Note that these variables can be accessed from a Bamboo build only when that build was triggered by releasing a version in Jira Software Server.
Jira variable | 説明 |
---|---|
${bamboo.jira.baseUrl} | The URL of your Jira application server. |
${bamboo.jira.projectKey} | The key of the triggering Jira application project. |
${bamboo.jira.projectName} | The name of the triggering Jira application project. |
${bamboo.jira.version} | The release version of the triggering Jira application project. |
${bamboo.jira.username} | リリース ビルドをトリガーしたユーザーのユーザー名 |
例
Maven の例
たとえば、Maven 2 バージョンを Bamboo で決定する場合、Maven 2 pom.xml
が次のようになる可能性があります。
...
<groupId>com.atlassian.boo</groupId>
<artifactId>boo-test</artifactId>
<packaging>jar</packaging>
<version>1.1.${bambooBuildNumber}-SNAPSHOT</version>
...
その後、ビルド計画の "目標" フィールドに次を指定できます。
clean package -DbambooBuildNumber=${bamboo.buildNumber}
コマンドが実行されると、Bamboo は buildNumber
を実際の番号 (1102 など) に置き換えます。この番号は、基盤となる Maven ビルドに渡されて使用されます。その後、コマンドは boo-test-1.1.1102-SNAPSHOT.jar
ような jar を生成します。
Ant の例
その後、ビルド計画の "ターゲット" フィールドに次を指定できます。
-f build.xml -DbambooBuildNumber=${bamboo.buildNumber}
コマンドが実行されると、Bamboo は buildNumber
を実際の番号 (1102 など) に置き換えます。この番号は、基盤となる Ant ビルドに渡されて使用されます。
機能を変数として指定する
グローバル変数と同じ方法で使用する機能を指定することもできます。
機能の形式は次のようにする必要があります。
${bamboo.capability.<capability_key>}
例:
カスタム
${bamboo.capability.<capability_key>}
JDK
${bamboo.capability.system.jdk.<jdk_label>}
ビルダー
${bamboo.capability.system.builder.<builder_type>.<builder_label>} e.g. ${bamboo.capability.system.builder.maven.Maven1}
perforce
${bamboo.capability.system.p4Executable}
If you select a capability, the specific capability key will be contained in the URL.
Please note, the space characters in the URL will be replaced with "+" characters. We recommend that you do not use capability labels with space characters, if you wish to use them as variables. A possible solution for space characters is to format them with "${}" symbols, however, this does not work in all cases.
機能を使用する
グローバル変数とビルド固有変数は、上記のとおり、ビルド計画の特定のフィールドで使用できます。機能については次のとおりです。
- System capabilities are available to all of these fields, (i.e. global and build-specific).
- Agent capabilities (i.e. agent-specific and shared/server capabilities) are available only to the build-specific fields. (i.e. not available to Repository URL, CVS Root or Branch name.)
例:
システム変数を指定しようとしているが、エージェントごとに異なる値を設定する場合は、次の手順を実行してください。
[ビルダー] タブのシステム環境変数フィールドとして次を設定します。
${bamboo.capability.thatsystemvariable}
- システム環境変数を各エージェントのカスタム機能として指定し、必要に応じて機能を異なる値に設定します。
廃止された変数
次の変数は廃止され、今後の Bamboo リリースでは削除されます。
一般的なリポジトリ変数 | |
---|---|
bamboo.repository.revision.number | リビジョン番号 |
bamboo.repository.branch.name | リポジトリ ブランチ名 (Bamboo バージョン 4.2 またはそれ以降) |
bamboo.repository.previous.revision.number | 前のリビジョン番号 (初期ビルドなどでは存在しない場合がある) |
Subversion | |
bamboo.custom.svn.revision.number | リビジョン番号 |
bamboo.custom.svn.lastchange.revision.number | 最後に変更されたリビジョン番号 |
bamboo.custom.svn.username | リポジトリ認証に使用されるユーザー名 |
bamboo.repository.svn.repositoryUrl | The repository URL. |
bamboo.planRepository.<position>.revision.number | リビジョン番号 |
bamboo.planRepository.<position>.lastchange.revision.number | 最後に変更されたリビジョン番号 |
CVS | |
bamboo.custom.cvs.last.update.time | 最終更新日のタイムスタンプ |
bamboo.custom.cvs.last.update.time.label | ポスト ビルド結果のラベリングのためのラベルとして使用される前回更新日のタイムスタンプ。cvs バージョン文字列内のスペースは「_」で置換されます。 |
perforce | |
bamboo.custom.p4.revision.number | 変更セット番号 |
bamboo.custom.p4.username | リポジトリ認証に使用されるユーザー名 |
bamboo.custom.p4.port | リポジトリ通信に使用されるポート |
bamboo.custom.p4.client | リポジトリ通信に使用されるクライアント |
Git | |
bamboo.repository.git.branch | ブランチ |
bamboo.repository.git.repositoryUrl | The repository URL. |
Mercurial | |
bamboo.repository.hg.repositoryUrl | The repository URL. |
bamboo.repository.hg.branch | ブランチ |
bamboo.repository.hg.username | リポジトリ認証に使用されるユーザー名 |