作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试针对 10 个实例上的 140 多个数据库为我们的数据库部署创建管道。我们的 IT 团队提到,在某些情况下,数据库会从一个实例移动到另一个实例以进行负载平衡。所以我不能相信每个版本的数据库都会保留在同一个实例上。我们还可以在没有我们的团队听到任何消息的情况下加入新客户。这意味着我必须编写一个只能动态部署到给定实例上的数据库的管道。每个实例都有一个单独的代理。
我现在计划的工作流程。
/*Pipeline Being Called*/
variables:
- name: BuildConfiguration
value: release
- name: BuildPlatform
value: any cpu
- name: system.debug
value: true
- name: datamode
value: 0
- name: APIMode
value: 0
- name: Instance
value: "[ServerInstance]"
- name: var01
trigger:
- FixingDRDeployments
stages:
- stage: Powershell
pool: [Agent Pool Name]
jobs:
- job: Powershell
steps:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$ServerInstance = "$(Instance)"
$Databases = Get-DbaDatabase -SqlInstance $ServerInstance
$ReturnValues = @()
$query = "
Query to validate database is one we want to deploy against.
"
foreach ( $db in $Databases) {
$Results = Invoke-DbaQuery -SqlInstance $serverInstance -Database $db.name -Query $query
if ($Results.Valid -eq 1) {
$ReturnValues += $db.Name
}
}
Write-Host $ReturnValues
#stages:
- template: deploytemplates/BuildTemplate.yml
- template: template.yml
parameters:
param: ["TestDatabase1","TestDatabase2"]
**^ Instead of having a defined set of static databases, I'd like to be able to pass an array of databases from the powershell script above.**
/*deploytemplates/BUildTemplate.yml*/
stages:
- stage: Build
jobs:
- job: build
pool:
name: mn-vs2017
demands:
- msbuild
- visualstudio
steps:
- task: VSBuild@1
displayName: 'Build solution **\*.sln'
inputs:
solution: '**\*.sln'
vsVersion: "15.0"
msbuildArgs: '/p:OutDir=$(build.artifactstagingdirectory) /p:CmdLineInMemoryStorage=True'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
clean: true
maximumCpuCount: true
msbuildArchitecture: x64
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: MasterDacPac'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
ArtifactName: DacPac
/*template.yml*/
parameters:
param : []
stages:
- stage: ApprovalGate1
displayName: ApprovalGate1
dependsOn: Build
jobs:
- deployment:
displayName: ApprovalGate1
pool: [Pool Name Here]
environment: Databases
strategy:
runOnce:
deploy:
steps:
- task: DownloadSecureFile@1
name: PublishProfile
displayName: 'Download secure file'
inputs:
secureFile: Production.publish.xml
- ${{ each p in parameters.param }}:
- task: SqlDacpacDeploymentOnMachineGroup@0
displayName: ${{ p }}
inputs:
DacpacFile: '$(Pipeline.Workspace)\DacPac\DacPacName.dacpac'
ServerName: $(Instance)
DatabaseName: ${{ p }}
PublishProfile: '$(PublishProfile.secureFilePath)'
continueOnError: true
condition: succeededOrFailed()
最佳答案
不,这是不可能的。如果您在 powershell 中创建一个变量,您将创建字符串类型的变量。 It is even worse :
Yaml variables have always been string: string mappings.
We are preparing to release a feature in the near future to allow you to pass more complex structures. Stay tuned!
steps:
- template: template.yaml
parameters:
instances:
- test1
- test2
server: someServer
关于azure-devops - 有没有办法在 powershell 中创建数组并在 Azure DevOps YAML 中循环遍历它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63623006/
我是一名优秀的程序员,十分优秀!