Bicep Deployタスクは、
この課題は以下の通りです:
- Bicepテンプレートを使ったAzureリソースの作成または更新
- 展開前にBicepテンプレートの検証
- 作戦の事前 What-If 変更点
- ライフサイクルポリシーを用いたデプロイスタックの管理
- デプロイメントおよびデプロイスタックの削除
- Bicep CLIバージョンの自動インストールと管理
この課題は以下を支えています:
-
ネイティブBicepサポート:
.bicepおよび.bicepparamファイルから、ARMテンプレートへの事前コンパイルを必要とせずに直接デプロイ - Deployment Stacks:Azureデプロイメントスタックの完全サポート(拒否設定、管理されないリソースポリシー、ライフサイクル管理)
- Automatic Bicep CLI Management: 指定されたCLIのバージョンを自動的にダウンロード・キャッシュBicep
- クロスプラットフォーム:Windows、Linux、macOSエージェントで動作
- 複数展開スコープ:リソースグループ、サブスクリプション、管理グループ、テナントスコープのサポート
- What-If Operations: 変更をAzure環境に適用する前にプレビューします
- 柔軟なパラメータ入力:インラインのYAML/JSONパラメータおよび従来型パラメータファイルのサポート
- 出力マスキング:秘密や接続文字列などの敏感な出力を自動的にマスキングします
構文
# Bicep Deploy v0
# Deploy and Manage Azure Resources using Bicep Files.
- task: BicepDeploy@0
inputs:
# Azure Details
type: 'deployment' # 'deployment' | 'deploymentStack'. Required. Execution type. Default: deployment.
#operation: 'create' # 'create' | 'validate' | 'whatIf' | 'delete'. Required when type = deployment || (type = deploymentStack && operation != whatIf). Operation. Default: create.
scope: 'resourceGroup' # 'resourceGroup' | 'subscription' | 'managementGroup' | 'tenant'. Required. Deployment scope. Default: resourceGroup.
#name: # string. Deployment name.
azureResourceManagerConnection: # string. Alias: ConnectedServiceName. Required. Azure Resource Manager connection.
#subscriptionId: # string. Required when scope != tenant && scope != managementGroup. Subscription.
resourceGroupName: # string. Required when scope = resourceGroup. Resource group.
#location: # string. Optional. Use when scope != resourceGroup. Location.
#tenantId: # string. Required when scope = tenant. Tenant ID.
#managementGroupId: # string. Required when scope = managementGroup. Management group ID.
# Template
#templateFile: # string. Template file.
#parametersFile: # string. Parameters file.
#parameters: # string. Override parameters.
# Deployment Stack Options
#actionOnUnmanageResources: 'detach' # 'delete' | 'detach'. Required when type = deploymentStack. Action on unmanaged resources. Default: detach.
#actionOnUnmanageResourceGroups: # 'delete' | 'detach'. Optional. Use when type = deploymentStack. Action on unmanaged resource groups.
#actionOnUnmanageManagementGroups: # 'delete' | 'detach'. Optional. Use when type = deploymentStack. Action on unmanaged management groups.
#denySettingsMode: 'none' # 'none' | 'denyDelete' | 'denyWriteAndDelete'. Required when type = deploymentStack. Deny settings mode. Default: none.
#denySettingsExcludedActions: # string. Optional. Use when type = deploymentStack && denySettingsMode != none. Deny settings excluded actions.
#denySettingsExcludedPrincipals: # string. Optional. Use when type = deploymentStack && denySettingsMode != none. Deny settings excluded principals.
#denySettingsApplyToChildScopes: false # boolean. Optional. Use when type = deploymentStack && denySettingsMode != none. Apply deny settings to child scopes. Default: false.
#bypassStackOutOfSyncError: false # boolean. Optional. Use when type = deploymentStack. Bypass stack out of sync error. Default: false.
# Advanced
#description: # string. Description.
#tags: # string. Optional. Use when type = deploymentStack. Tags.
#bicepVersion: # string. Bicep version.
#maskedOutputs: # string. Masked outputs.
#environment: 'azureCloud' # 'azureCloud' | 'azureChinaCloud' | 'azureGermanCloud' | 'azureUSGovernment'. Azure environment. Default: azureCloud.
#whatIfExcludeChangeTypes: # string. Optional. Use when operation = whatIf. What-If exclude change types.
#validationLevel: # 'provider' | 'template' | 'providerNoRbac'. Optional. Use when type = deployment && (operation = validate || operation = whatIf). Validation level.
入力
type
-
実行タイプ
string。 必須。 許可される値: deployment、 deploymentStack (デプロイメントスタック)。 既定値: deployment。
実行タイプを指定する:deploymentまたはdeploymentStack。
operation
-
動作
string。
type = deployment || (type = deploymentStack && operation != whatIf)時に必要です。 許可される値: create (作成または更新)、 validate、 whatIf (What-If(プレビューの変更))、 delete。 既定値: create。
実行すべき操作を指定します。 デプロイメントサポート:作成、検証、whatIf。 デプロイメントスタックは、作成、検証、削除をサポートします。
scope
-
展開範囲
string。 必須。 許可値: resourceGroup (リソースグループ)、 subscription、 managementGroup (管理グループ)、 tenant。 既定値: resourceGroup。
リソースの配分範囲を指定します。
name
-
展開名
string。
デプロイメントまたはデプロイスタックの名前を指定します。 指定しない場合は、既定の名前が生成されます。
azureResourceManagerConnection
-
Azure Resource Manager 接続
入力エイリアス: ConnectedServiceName。
string。 必須。
Select the Azure Resource Manager service connection.
subscriptionId
-
購読
string。
scope != tenant && scope != managementGroup時に必要です。
Azureサブスクリプションを選択してください。 スコープがサブスクリプションやリソースグループの場合は必須です。
resourceGroupName
-
リソース グループの
string。
scope = resourceGroup時に必要です。
リソースグループの名前を教えてください。
location
-
所在地
string。 オプション。
scope != resourceGroupするときに使用します。
展開メタデータを保存する場所。 サブスクリプション、管理グループ、テナントの範囲に必須です。
tenantId
-
テナントID
string。
scope = tenant時に必要です。
テナントIDを指定します。 賃貸者の範囲であれば必須です。
managementGroupId
-
管理グループID
string。
scope = managementGroup時に必要です。
管理グループIDを指定します。 管理グループの範囲であれば必須です。
templateFile
-
テンプレートファイル
string。
Bicepテンプレートファイル(.bicep)へのパスを指定します。
parametersFile
-
パラメータファイル
string。
パラメータファイルへのパス(.json または.bicepparam)を指定します。
parameters
-
オーバーライド パラメーター
string。
インラインパラメータをJSONまたはYAMLオブジェクトとして指定してください。 例:{"param1": "value1", "param2": "value2"}。
actionOnUnmanageResources
-
管理されていない資源に対する措置
string。
type = deploymentStack時に必要です。 使用できる値: delete、detach。 既定値: detach。
テンプレートに定義されていないリソースに対して取るべきアクションを指定します。
actionOnUnmanageResourceGroups
-
管理されていないリソースグループへの行動
string。 オプション。
type = deploymentStackするときに使用します。 使用できる値: delete、detach。
テンプレートに定義されていないリソースグループに対して取るべきアクションを指定します。
actionOnUnmanageManagementGroups
-
管理されていない管理グループに対する措置
string。 オプション。
type = deploymentStackするときに使用します。 使用できる値: delete、detach。
テンプレートに定義されていない管理グループに対して取るべきアクションを指定します。
denySettingsMode
-
設定拒否モード
string。
type = deploymentStack時に必要です。 許可される値: none、 denyDelete (削除拒否)、 denyWriteAndDelete (書き込み・削除拒否)。 既定値: none。
不正な変更を防ぐために拒否設定のモードを指定します。
denySettingsExcludedActions
-
拒否設定 除外アクション
string。 オプション。
type = deploymentStack && denySettingsMode != noneするときに使用します。
拒否設定から除外するアクションのカンマ区切りリスト。
denySettingsExcludedPrincipals
-
否定設定はプリンシパルを除外した
string。 オプション。
type = deploymentStack && denySettingsMode != noneするときに使用します。
拒否設定から除外する主要IDのカンマ区切りリスト。
denySettingsApplyToChildScopes
-
子スコープに拒否設定を適用する
boolean。 オプション。
type = deploymentStack && denySettingsMode != noneするときに使用します。 既定値: false。
有効化すると、管理されたリソースの子スコープにも拒否設定が適用されます。
bypassStackOutOfSyncError
-
バイパススタックの同期外エラー
boolean。 オプション。
type = deploymentStackするときに使用します。 既定値: false。
デプロイスタックが同期していない場合のエラーを回避します。
description
-
説明の
string。
デプロイメントまたはデプロイスタックの説明。
tags
-
タグの
string。 オプション。
type = deploymentStackするときに使用します。
タグはJSONまたはYAMLオブジェクトとして使います。 例:「環境」:「開発」、「オーナー」:「チーム名」}。
bicepVersion
-
Bicep バージョン
string。
使用するBicepのバージョン(例:'0.38.5')を指定します。 提供されていない場合は、最新バージョンが使用されます。
maskedOutputs
-
マスク出力
string。
出力名をカンマ区切ってマスの値(例:シークレット)にまとめたリスト。
environment
-
Azure environment
string。 許可される値:azureCloud(Azureクラウド)、azureChinaCloud(Azure中国クラウド)、azureGermanCloud(Azureドイツクラウド)、azureUSGovernment(Azure 米国政府機関)。 既定値: azureCloud。
使用するAzure環境を指定します。
whatIfExcludeChangeTypes
-
What-If 変更タイプを除外します
string。 オプション。
operation = whatIfするときに使用します。
操作から除外する変更タイプのカンマ区切りリスト(例:noChange、無視)What-If。
validationLevel
-
検証レベル
string。 オプション。
type = deployment && (operation = validate || operation = whatIf)するときに使用します。 許可される値: provider、 template、 providerNoRbac (プロバイダー(RBACなし))。
デプロイ作業の検証レベル。
タスク コントロールのオプション
すべてのタスクには、タスク入力に加えて制御オプションがあります。 詳細については、「コントロール オプションと一般的なタスク プロパティを参照してください。
出力変数
なし。
注釈
前提条件
Azure サブスクリプション
Azureにデプロイするには、Azureサブスクリプションをサービス接続を使ってAzure Pipelinesに接続する必要があります:
- Project設定 → Service connections
- 新しいサービス接続は
Azure Resource Manager - 認証方法を選択してください:
- Service Principal(自動) - ほとんどのシナリオで推奨
- Service Principal(マニュアル) - 高度な構成用
- 管理型アイデンティティ - 管理型アイデンティティを持つAzureホストエージェント向け
- ワークロード・アイデンティティ・フェデレーション - 秘密なしで強化されたセキュリティのために
サービス接続のトラブルシューティングについては、Azure RMエンドポイントドキュメントを参照してください。
エージェントの要件
- 最小エージェントバージョン:2.144.0
- 対応OS:Windows、Linux、macOS
- Node.js:Node.js 20以上(現代のホストエージェントに含まれます)
- Bicep CLI:タスクによって自動的にインストールされます(手動インストールは不要)
展開出力
タスクはBicepテンプレートで定義されたすべての出力に対して自動的にパイプライン変数を作成します。 これらの変数は後のタスクで活用可能です。
Bicepでの出力定義
出力はBicepテンプレート内でoutputキーワードを用いて定義されます。 例えば次が挙げられます。
output storageAccountName string = storageAccount.name
output webAppUrl string = webApp.properties.defaultHostName
output intOutput int = 42
output objectOutput object = {
key1: 'value1'
key2: 'value2'
}
詳細な指針については、Bicep Outputsドキュメントを参照してください。
出力が利用可能になる方法
デプロイが成功裏に完了すると、すべての出力がタスクステップの出力変数として設定されます。 次のタスクで参照するには、BicepDeployステップを name し、構文 $(stepName.outputName)を使いましょう。
PowerShellでの出力アクセス
- task: BicepDeploy@0
name: deploy
displayName: 'Deploy Infrastructure'
inputs:
azureResourceManagerConnection: 'Azure-Connection'
subscriptionId: '$(subscriptionId)'
resourceGroupName: 'my-resource-group'
templateFile: 'infra/main.bicep'
- task: PowerShell@2
displayName: 'Use Deployment Outputs'
inputs:
targetType: 'inline'
script: |
Write-Host "Storage Account Name: $(deploy.storageAccountName)"
Write-Host "Web App URL: $(deploy.webAppUrl)"
Bashでの出力アクセス
- task: BicepDeploy@0
name: deploy
displayName: 'Deploy Infrastructure'
inputs:
azureResourceManagerConnection: 'Azure-Connection'
subscriptionId: '$(subscriptionId)'
resourceGroupName: 'my-resource-group'
templateFile: 'infra/main.bicep'
- task: Bash@3
displayName: 'Use Deployment Outputs'
inputs:
targetType: 'inline'
script: |
echo "Storage Account Name: $(deploy.storageAccountName)"
echo "Web App URL: $(deploy.webAppUrl)"
例示
例1:基本展開
- task: BicepDeploy@0
displayName: 'Deploy Bicep Template'
inputs:
azureResourceManagerConnection: 'Azure-Connection'
subscriptionId: '$(subscriptionId)'
resourceGroupName: 'my-resource-group'
templateFile: 'infra/main.bicep'
parametersFile: 'infra/main.bicepparam'
例2:デプロイメントスタック
- task: BicepDeploy@0
displayName: 'Deploy with Stack Protection'
inputs:
type: 'deploymentStack'
operation: 'create'
name: 'production-stack'
azureResourceManagerConnection: 'Azure-Connection'
subscriptionId: '$(subscriptionId)'
resourceGroupName: 'production-rg'
templateFile: 'infra/main.bicep'
parametersFile: 'infra/production.bicepparam'
actionOnUnmanageResources: 'delete'
denySettingsMode: 'denyWriteAndDelete'
例3:Subscription-Level 展開
- task: BicepDeploy@0
displayName: 'Deploy Subscription Resources'
inputs:
scope: 'subscription'
azureResourceManagerConnection: 'Azure-Connection'
subscriptionId: '$(subscriptionId)'
location: 'eastus'
templateFile: 'infra/subscription.bicep'
parametersFile: 'infra/subscription.bicepparam'