YAML 文件中的问题

Issue in YAMEL file

我正在使用 Azure DevOps 构建和部署我的 Azure Synapse

我有两个 YAML 文件。第一个效果很好,我需要分开构建和发布步骤。因此,我写了第二个 YAML 文件。第二个 YAML 文件有此错误:

##[error]No files were found to deploy with search pattern 
d:\a\s\SQL_ASynapse\bin\Release\SQL_ASynapse.dacpacCheck out how to troubleshoot failures at 
https://aka.ms/sqlazuredeployreadme#troubleshooting-

第一个运行良好的 YAML 文件:

trigger:
- master

pool:
    vmImage: 'windows-latest'

variables:
    solution: '**/*.sln'
    buildPlatform: 'Any CPU'
    buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
    inputs:
    restoreSolution: '$(solution)'

- task: AzureKeyVault@1
    inputs:
    azureSubscription: 'XXX'
    KeyVaultName: 'XXX-Dev'
    SecretsFilter: '*'

- task: VSBuild@1
    inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
    inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: SqlAzureDataWarehouseDacpacDeployment@1
    inputs:
    azureSubscription: 'XXX'
    AuthenticationType: 'server'
    ServerName: 'XXX'
    DataWarehouse: '$(SynapseName)'
    SqlUsername: '$(SynapseSQLUsername)'
    SqlPassword: '$(SynapseSQLPassword)'
    deployType: 'DacpacTask'
    DeploymentAction: 'Publish'
    DacpacFile: 'SQL_ASynapse\bin\Release\SQL_ASynapse.dacpac'
    IpDetectionMethod: 'AutoDetect'

第二个有错误的 YAML 文件:

trigger:
- master

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  # Agent VM image name
  vmImageName: 'windows-latest'

stages:
- stage: Build
  displayName: Build stage

  jobs:
  - job: Build
    displayName: Build
    pool:  
      vmImage: $(vmImageName)

    steps:
    - task: NuGetToolInstaller@1

    - task: NuGetCommand@2
      inputs:
        restoreSolution: '$(solution)'

    - task: VSBuild@1
      inputs:
        solution: '$(solution)'
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'

    - task: VSTest@2
      inputs:
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'

- stage: Deploy
  displayName: Deploy stage
  dependsOn: Build
  condition: succeeded()

  jobs:
  - deployment: Deploy
    displayName: Deploy
    environment: 'development'
    pool:
      vmImage: $(vmImageName)

    strategy:
      runOnce:
        deploy:
          steps:
          - task: AzureKeyVault@1
            inputs:
              azureSubscription: 'XXX-Dev'
              KeyVaultName: 'XXX-Dev'
              SecretsFilter: '*'

          - task: SqlAzureDataWarehouseDacpacDeployment@1
            inputs:
              azureSubscription: 'XXX-Dev'
              AuthenticationType: 'server'
              ServerName: 'XXX'
              DataWarehouse: '$(SynapseName)'
              SqlUsername: '$(SynapseSQLUsername)'
              SqlPassword: '$(SynapseSQLPassword)'
              deployType: 'DacpacTask'
              DeploymentAction: 'Publish'
              DacpacFile: 'SQL_ASynapse\bin\Release\SQL_ASynapse.dacpac'
              IpDetectionMethod: 'AutoDetect'

@Levi Lu-MSFT 答案更新#1

我已经像下面的代码一样更改了我的第二个脚本:

...
- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
- publish: $(system.defaultworkingdirectory)\SQL_ASynapse\bin\Release ## path to a file or folder
  artifact: MyBuildOutputs
...

      - download: current  # refers to artifacts published by current pipeline
        artifact: MyBuildOutputs

      - task: SqlAzureDataWarehouseDacpacDeployment@1
        inputs:
          azureSubscription: 'xxx-Dev'
          AuthenticationType: 'server'
          ServerName: 'xxx.database.windows.net'
          DataWarehouse: '$(SynapseName)'
          SqlUsername: '$(SynapseSQLUsername)'
          SqlPassword: '$(SynapseSQLPassword)'
          deployType: 'DacpacTask'
          DeploymentAction: 'Publish'
          DacpacFile: 'SQL_ASynapse\bin\Release\SQL_ASynapse.dacpac'
          IpDetectionMethod: 'AutoDetect'

但我仍然有同样的错误。

上传任务结果

下载任务结果

SqlAzureDataWarehouseDacpacDeployment 错误:

##[错误]找不到要使用搜索模式部署的文件 d:\a\s\SQL_ASynapse\bin\Release\SQL_ASynapse.dacpac 查看如何 解决 https://aka.ms/sqlazuredeployreadme#troubleshooting-

的故障

如果您使用 Microsoft 托管的代理。 yaml 管道中定义的每个作业都将 运行 在全新的虚拟机上。虚拟机用完就被丢弃

因此在部署阶段的部署作业的代理计算机上不存在构建阶段的生成作业的构建工件。这就是你出现上述错误的原因。

您需要在构建作业中的 Vsbuild 任务后添加一个 publish task 以将构建结果发布到 azure devops 服务器。您应该指定要发布的正确路径(构建工件所在的位置)。

- publish: $(system.defaultworkingdirectory)\SQL_ASynapse\bin\Release ## path to a file or folder
  artifact: MyBuildOutputs

然后在Deploy job中的qlAzureDataWarehouseDacpacDeployment任务之前添加一个download task来下载构建结果来部署job agent。这样构建结果将可用于部署任务。

- download: current  # refers to artifacts published by current pipeline
  artifact: MyBuildOutputs

要发布和下载构建工件,您还可以使用 Publish Build Artifacts task, Download Build Artifacts task

更新:

当您使用下载任务时:请参阅here了解更多信息。

By default, files are downloaded to $(Pipeline.Workspace)/{artifact}, where artifact is the name of the artifact. The folder structure of the artifact is always preserved.

你可以从上面更新的截图中看到。工件已下载到文件夹 D:\a\MyBuildOutputs

所以你应该设置 DacpacFile 属性如下:

DacpacFile : $(Pipeline.Workspace)/MyBuildOutputs/SQL_ASynapse.dacpac