Skip to content

Commit

Permalink
Added AzureDevOps pool registration
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderSehr committed Mar 4, 2022
1 parent e19d2a8 commit 45b89c0
Show file tree
Hide file tree
Showing 36 changed files with 1,235 additions and 796 deletions.
172 changes: 101 additions & 71 deletions .azuredevops/azureDevOpsScaleSet/.templates/pipeline.scaleset.jobs.yml
Original file line number Diff line number Diff line change
@@ -1,83 +1,113 @@
parameters:
- name: environment
default:
- name: deploymentsToPerform
default:
- name: serviceConnection
default:
- name: waitForscalesetBuild
default:
- name: environment
default:
- name: deploymentsToPerform
default:
- name: serviceConnection
default:
- name: waitForscalesetBuild
default:
- name: setAgentPool
default:

jobs:
- deployment: deploy_job
displayName: Deploy Resources
environment: ${{ parameters.environment }}
timeoutInMinutes: 120
pool:
vmImage: '$(vmImage_${{ parameters.environment }})'
name: '$(poolName_${{ parameters.environment }})'
strategy:
runOnce:
deploy:
steps:
- checkout: self
# [Deployment] task(s)
#---------------------
- task: AzurePowerShell@4
displayName: 'Deploy [scaleset.deploy.bicep] via service connection [$(serviceConnection_${{ parameters.environment }})]'
name: deploy_task
inputs:
azureSubscription: '$(serviceConnection_${{ parameters.environment }})'
ScriptType: InlineScript
inline: |
# Load used functions
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(sharedOrchestrationFunctionsPath)' 'deployment' 'New-ModuleDeployment.ps1')
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(sharedOrchestrationFunctionsPath)' 'deployment' 'Test-TemplateWithParameterFile.ps1')
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(sharedOrchestrationFunctionsPath)' 'deployment' 'Set-CustomParameter')
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(orchestrationFunctionsPath)' 'image' 'Select-Image.ps1')
- deployment: deploy_job
displayName: Deploy Resources
environment: ${{ parameters.environment }}
timeoutInMinutes: 120
pool:
vmImage: '$(vmImage_${{ parameters.environment }})'
name: '$(poolName_${{ parameters.environment }})'
strategy:
runOnce:
deploy:
steps:
- checkout: self
# [Deployment] task(s)
#---------------------
- task: AzurePowerShell@4
displayName: 'Deploy [scaleset.deploy.bicep] via service connection [$(serviceConnection_${{ parameters.environment }})]'
name: deploy_task
inputs:
azureSubscription: '$(serviceConnection_${{ parameters.environment }})'
ScriptType: InlineScript
inline: |
# Load used functions
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(sharedOrchestrationFunctionsPath)' 'deployment' 'New-ModuleDeployment.ps1')
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(sharedOrchestrationFunctionsPath)' 'deployment' 'Test-TemplateWithParameterFile.ps1')
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(sharedOrchestrationFunctionsPath)' 'deployment' 'Set-CustomParameter')
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(orchestrationFunctionsPath)' 'image' 'Select-Image.ps1')
# Check the provide image
$parameterFilePath = Join-Path '$(parametersPath)' '${{ parameters.environment }}.scaleset.parameters.json'
$parameterFileContent = ConvertFrom-Json (Get-Content $parameterFilePath -Raw) -AsHashTable
if($imageVersionReference = Select-Image -imageReference $parameterFileContent.parameters.vmssParam.value.imageReference -Verbose) {
$customValueMap += @{
path = 'vmssParam.value.imageReference.id'
value = $imageVersionReference
}
}
# Check the provide image
$parameterFilePath = Join-Path '$(parametersPath)' '${{ parameters.environment }}.scaleset.parameters.json'
$parameterFileContent = ConvertFrom-Json (Get-Content $parameterFilePath -Raw) -AsHashTable
# Overwrite parameter file if necessary
if($customValueMap.Count -gt 0) {
$overwriteInputObject = @{
if($imageVersionReference = Select-Image -imageReference $parameterFileContent.parameters.vmssParam.value.imageReference -Verbose) {
$customValueMap += @{
path = 'vmssParam.value.imageReference.id'
value = $imageVersionReference
}
}
# Overwrite parameter file if necessary
if($customValueMap.Count -gt 0) {
$overwriteInputObject = @{
parameterFilePath = $parameterFilePath
valueMap = $customValueMap
}
Set-CustomParameter @overwriteInputObject
}
# ----------------- #
# INVOKE DEPLOYMENT #
# ----------------- #
$functionInput = @{
templateFilePath = Join-Path '$(templatesPath)' 'scaleset.deploy.bicep'
parameterFilePath = $parameterFilePath
valueMap = $customValueMap
location = '$(location)'
subscriptionId = (Get-AzContext).Subscription.Id
}
Set-CustomParameter @overwriteInputObject
}
# ----------------- #
# INVOKE DEPLOYMENT #
# ----------------- #
$functionInput = @{
templateFilePath = Join-Path '$(templatesPath)' 'scaleset.deploy.bicep'
parameterFilePath = $parameterFilePath
location = '$(location)'
subscriptionId = (Get-AzContext).Subscription.Id
}
# Inject control parmaeters from pipeline
$functionInput['additionalParameters'] = @{
deploymentsToPerform = '${{ parameters.deploymentsToPerform }}'
}
# Inject control parmaeters from pipeline
$functionInput['additionalParameters'] = @{
deploymentsToPerform = '${{ parameters.deploymentsToPerform }}'
}
Write-Verbose "Invoke task with" -Verbose
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose
Write-Verbose "Invoke task with" -Verbose
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose
# Validate deployment
Test-TemplateWithParameterFile @functionInput
# Invoke deployment
New-ModuleDeployment @functionInput -Verbose
errorActionPreference: stop
azurePowerShellVersion: LatestVersion
- task: PowerShell@2
displayName: Register scale set
condition: |
and(
succeeded(),
eq('${{ parameters.setAgentPool }}', 'true')
)
inputs:
targetType: inline
pwsh: true
script: |
# Load used functions
. (Join-Path '$(System.DefaultWorkingDirectory)' '$(orchestrationFunctionsPath)' 'registerScaleSet' 'Register-ElasticPool.ps1')
$parameterFilePath = Join-Path '$(parametersPath)' '${{ parameters.environment }}.agentpool.parameters.json'
$parameterFileContent = ConvertFrom-Json (Get-Content $parameterFilePath -Raw) -AsHashTable
$inputObject = @{
Organization = $parameterFileContent.Organization
Project = $parameterFileContent.Project
ServiceConnectionName = $parameterFileContent.ServiceConnectionName
AgentPoolProperties = $parameterFileContent.AgentPoolProperties
}
# Validate deployment
Test-TemplateWithParameterFile @functionInput
Write-Verbose "Invoke task with" -Verbose
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose
# Invoke deployment
New-ModuleDeployment @functionInput -Verbose
errorActionPreference: stop
azurePowerShellVersion: LatestVersion
Sync-ElasticPool @inputObject
84 changes: 44 additions & 40 deletions .azuredevops/azureDevOpsScaleSet/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,54 @@
name: 'ScaleSet Deployment'

parameters:
- name: startEnvironment
displayName: Environment to start from
type: string
default: sbx
values:
- sbx
- dev
- prd
- name: deploymentsToPerform
displayName: Scope of deployment
type: string
default: Only Scale Set
values:
- All
- Only Scale Set
- name: startEnvironment
displayName: Environment to start from
type: string
default: sbx
values:
- sbx
- dev
- prd
- name: deploymentsToPerform
displayName: Scope of deployment
type: string
default: Only Scale Set
values:
- All
- Only Scale Set
- name: setAgentPool
displayName: Add/Update agent pool
type: boolean
default: true
variables:
- template: variables.yml
- template: variables.yml

trigger: none

stages:
- stage: SBX_Deployments
displayName: Deploy to SBX
condition: and(succeeded(), eq('${{ parameters.startEnvironment }}', 'sbx'))
jobs:
- template: .templates/pipeline.scaleset.jobs.yml
parameters:
environment: 'sbx'
deploymentsToPerform: '${{ parameters.deploymentsToPerform }}'
- stage: SBX_Deployments
displayName: Deploy to SBX
condition: and(succeeded(), eq('${{ parameters.startEnvironment }}', 'sbx'))
jobs:
- template: .templates/pipeline.scaleset.jobs.yml
parameters:
environment: 'sbx'
deploymentsToPerform: '${{ parameters.deploymentsToPerform }}'

- stage: DEV_Deployments
displayName: Deploy to DEV
condition: and(succeeded(), in('${{ parameters.startEnvironment }}', 'sbx', 'dev'))
jobs:
- template: .templates/pipeline.scaleset.jobs.yml
parameters:
environment: 'dev'
deploymentsToPerform: '${{ parameters.deploymentsToPerform }}'
- stage: DEV_Deployments
displayName: Deploy to DEV
condition: and(succeeded(), in('${{ parameters.startEnvironment }}', 'sbx', 'dev'))
jobs:
- template: .templates/pipeline.scaleset.jobs.yml
parameters:
environment: 'dev'
deploymentsToPerform: '${{ parameters.deploymentsToPerform }}'

- stage: PRD_Deployments
displayName: Deploy to PRD
condition: and(succeeded(),in('${{ parameters.startEnvironment }}', 'sbx', 'dev', 'prd'))
jobs:
- template: .templates/pipeline.scaleset.jobs.yml
parameters:
environment: 'prd'
deploymentsToPerform: '${{ parameters.deploymentsToPerform }}'
- stage: PRD_Deployments
displayName: Deploy to PRD
condition: and(succeeded(),in('${{ parameters.startEnvironment }}', 'sbx', 'dev', 'prd'))
jobs:
- template: .templates/pipeline.scaleset.jobs.yml
parameters:
environment: 'prd'
deploymentsToPerform: '${{ parameters.deploymentsToPerform }}'
20 changes: 10 additions & 10 deletions .azuredevops/azureDevOpsScaleSet/variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@
#######################################################################

variables:
#############
## GENERAL ##
#############
#region shared
#############
## GENERAL ##
#############
#region shared
vmImage_sbx: 'ubuntu-latest' # Use this for microsoft-hosted agents
vmImage_dev: 'ubuntu-latest' # Use this for microsoft-hosted agents
vmImage_prd: 'ubuntu-latest' # Use this for microsoft-hosted agents
poolName_sbx: '' # Use this for self-hosted agents
poolName_dev: '' # Use this for self-hosted agents
poolName_prd: '' # Use this for self-hosted agents

poolName_sbx: '' # Use this for self-hosted agents
poolName_dev: '' # Use this for self-hosted agents
poolName_prd: '' # Use this for self-hosted agents

serviceConnection_sbx: 'sbxConnection'
serviceConnection_dev: 'devConnection'
serviceConnection_prd: 'prdConnection'
#endregion
#endregion

#region specific
#region specific
templatesPath: 'constructs/azureDevOpsScaleSet/templates'
parametersPath: 'constructs/azureDevOpsScaleSet/parameters'
orchestrationFunctionsPath: 'constructs/azureDevOpsScaleSet/scripts'
Expand Down
Loading

0 comments on commit 45b89c0

Please sign in to comment.