-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathazure-pipeline-infrastructure.yml
More file actions
114 lines (101 loc) · 4.09 KB
/
Copy pathazure-pipeline-infrastructure.yml
File metadata and controls
114 lines (101 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Azure Infrastructure Pipeline
# This pipeline deploys the Azure infrastructure using Bicep templates
# and outputs the resource information for use by other pipelines
trigger:
branches:
include:
- main
paths:
include:
- infra/*
# Manual trigger support
pr: none
parameters:
- name: environmentName
displayName: Environment Name
type: string
default: 'conmig'
- name: resourceGroupName
displayName: Resource Group Name
type: string
default: 'rg-conmig-dev'
- name: containerRegistryEndpoint
displayName: Container Registry Endpoint (exclude https://)
type: string
default: 'acrcontainermigrationdev.azurecr.io'
- name: tags
displayName: Resource Tags
type: object
default: {}
- name: enableMonitoring
displayName: Enable Monitoring
type: boolean
default: true
variables:
azureServiceConnection: 'azureserviceconnection'
vmImageName: 'ubuntu-latest'
envName: ${{ parameters.environmentName }}
resourceGroupName: ${{ parameters.resourceGroupName }}
containerRegistryEndpoint: ${{ parameters.containerRegistryEndpoint }}
tags: ${{ convertToJson(parameters.tags) }}
enableMonitoring: ${{ parameters.enableMonitoring }}
stages:
- stage: Infrastructure
displayName: Deploy Infrastructure
jobs:
- job: DeployInfrastructure
displayName: Deploy Azure Infrastructure
pool:
vmImage: $(vmImageName)
steps:
- task: AzureCLI@2
displayName: 'Deploy Infrastructure with Bicep'
inputs:
azureSubscription: $(azureServiceConnection)
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
set -e # Exit immediately if any command fails
set -o pipefail # Ensure pipeline failures are caught
echo "Deploying infrastructure with Bicep..."
echo "Environment Name: $(envName)"
echo "Resource Group: $(resourceGroupName)"
# Deploy infrastructure and capture outputs
echo "Starting Bicep deployment..."
# Deploy Bicep template with explicit error handling
echo "Executing Bicep deployment..."
DEPLOYMENT_OUTPUT=$(az deployment group create \
--name "deploy.$(envName).$(Build.BuildId)" \
--resource-group $(resourceGroupName) \
--template-file $(Build.SourcesDirectory)/infra/main.bicep \
--parameters solutionName=$(envName) containerRegistryEndpoint='$(containerRegistryEndpoint)' tags='$(tags)' enableMonitoring=$(enableMonitoring) \
--query "properties.outputs" \
--output json) || {
echo "❌ ERROR: Bicep deployment failed!"
echo "Deployment name: deploy.$(envName).$(Build.BuildId)"
echo "Resource group: $(resourceGroupName)"
echo "Template file: $(Build.SourcesDirectory)/infra/main.bicep"
echo "Parameters: solutionName=$(envName) containerRegistryEndpoint='$(containerRegistryEndpoint)'"
# Try to get deployment error details
echo "Attempting to retrieve deployment error details..."
az deployment group show \
--name "deploy.$(envName).$(Build.BuildId)" \
--resource-group $(resourceGroupName) \
--query "properties.error" \
--output json || echo "Could not retrieve deployment error details"
exit 1
}
# Validate deployment output
if [ -z "$DEPLOYMENT_OUTPUT" ] || [ "$DEPLOYMENT_OUTPUT" = "null" ]; then
echo "❌ ERROR: Deployment completed but no output was returned."
exit 1
fi
echo "✅ Infrastructure deployment completed successfully!"
echo "Raw deployment outputs: $DEPLOYMENT_OUTPUT"
# Create summary of deployed resources
echo "=== Infrastructure Deployment Summary ==="
echo "Environment: $(envName)"
echo "Resource Group: $(resourceGroupName)"
echo "Location: $RG_LOCATION"
echo "Deployment completed at: $(date)"
echo "============================================"