[英]Azure Devops YAML Pipelines - While loop?
Azure 发布管道 (YAML) 中是否有 while 循环这样的东西? 我的用例是我正在使用 runOnce 策略将工件部署到干净的环境中,部署客户端数据,在移动到下一个客户端之前,我需要运行查询以确保完成所有处理并完成健康检查。 所有检查都可以通过 SQL 脚本在 Azure SQL 数据库中完成,最终我需要将结果和任务时间与预期的集合进行比较。
即跨分支处理客户数据是否产生预期的结果和时间。
如果有更简单的方法,可能是一个方形钉圆孔,很高兴使用不同的方法。
- 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'
each
关键字,它相当于for loop
。each
语句来运行多个任务。GATE
来控制部署。 它们主要用于基础设施的健康检查、部署的外部批准等。参考:
Azure Devops YAML 管道 - While 循环?
您可以创建一个模板,该模板将包含一组Check if processing finished
的任务,并在构建期间将循环时间作为参数传递,例如:
- template: CheckProcessingFinished.yaml
parameters:
param: ["1","2","3"]
CheckProcessingFinished.yaml:
parameters:
param : []
steps:
- ${{each Looptimes in parameters.param}}:
- 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'
- task: PowerShell@2
inputs:
targetType: 'Sleep 30 seconds'
script: |
Start-Sleep 30
您可以查看文档解决 Azure DevOps Pipelines 中的循环问题以获取更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.