Is there such a thing in Azure Release Pipelines (YAML) as a while loop? My use case is that I am using runOnce strategy to deploy artifacts to a clean environment, deploy a clients data and before I move onto the next client I need to run a query to ensure all the processing is finished and health checks are done. All checks can be done via SQL scripts into an Azure SQL Database and eventually I need to compare the results and task timings against an expected set.
i.e Does processing the client data across branches yield the expected results and timings.
Might be a square peg round hole so happy to use a different approach if there is an easier way.
- deployment : Install
pool:
vmImage: ubuntu-latest
environment:
name: 'Test_Env'
resourceType: VirtualMachine
strategy:
runOnce:
deploy:
steps:
# Remove and re-create blank database on the Elastic Pool.
- task: SqlAzureDacpacDeployment@1
displayName: Drop DB
inputs:
azureSubscription: 'Azure'
AuthenticationType: 'server'
ServerName: '$(DB_SERVER)'
DatabaseName: 'master'
SqlUsername: '$(DB_USERNAME)'
SqlPassword: '$(DB_PASSWORD)'
deployType: 'InlineSqlTask'
SqlInline: |
IF EXISTS (SELECT name FROM master.sys.databases WHERE name = N'$(DB_DATABASE)') DROP DATABASE [$(DB_DATABASE)]
IpDetectionMethod: 'AutoDetect'
- task: SqlAzureDacpacDeployment@1
displayName: Create DB
inputs:
azureSubscription: 'Azure'
AuthenticationType: 'server'
ServerName: '$(DB_SERVER)'
DatabaseName: 'master'
SqlUsername: '$(DB_USERNAME)'
SqlPassword: '$(DB_PASSWORD)'
deployType: 'InlineSqlTask'
SqlInline: |
CREATE DATABASE $(DB_DATABASE) ( SERVICE_OBJECTIVE = ELASTIC_POOL (name = [SQL_ElasticPool] ));
IpDetectionMethod: 'AutoDetect'
- task: CmdLine@2
displayName: Install Product
inputs:
script: |
start /wait msiexec.exe /i "$(System.ArtifactsDirectory)installer.msi" client_data= $(client_data) DB_USERNAME=$(DB_USERNAME) DB_PASSWORD=$(DB_PASSWORD)
workingDirectory: $(System.ArtifactsDirectory)
- task: CmdLine@2
displayName: Start Service
inputs:
script: |
sc start $(WIN_SERVICE)
# This is where I would want a while-loop
- task: SqlAzureDacpacDeployment@1
displayName: Check if processing finished
inputs:
azureSubscription: 'Azure'
AuthenticationType: 'server'
ServerName: '$(DB_SERVER)'
DatabaseName: '$(DB_DATABASE)'
SqlUsername: '$(DB_USERNAME)'
SqlPassword: '$(DB_PASSWORD)'
deployType: 'InlineSqlTask'
SqlInline: |
select 1 from eventlog if complete = 0
IpDetectionMethod: 'AutoDetect'
2
Answers
each
keyword, and it is an equivalent of thefor loop
.task either by writing them one by one or by using the
each
statement which is equivalent to a for loop.
GATE
which is a way to control a deployment. They are predominantly used for heath checkups of infrastructure, external approvals for deployment, etc.the pipeline.
Refence:
Azure Pipeline Gate
You could create a template which will have a set of
Check if processing finished
task, and pass loop time as parameters across during your build, like:CheckProcessingFinished.yaml:
You could check the document Solving the looping problem in Azure DevOps Pipelines for some more details.