-1

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

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

##[error]No files were found to deploy with search pattern 
d:\a\1\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\1\s\SQL_ASynapse\bin\Release\SQL_ASynapse.dacpac 部署的文件在https://aka.ms/sqlazuredeployreadme#troubleshooting-查看如何解决故障

4

1 回答 1

1

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

因此,来自 Build 阶段的 Build 作业的构建工件不存在于 Deploy 阶段的部署作业的代理机器上。这就是你得到上述错误的原因。

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

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

然后在 Deploy 作业中的 qlAzureDataWarehouseDacpacDeployment任务之前添加下载任务,以下载构建结果以部署作业代理。这样构建结果将可用于部署任务。

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

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

更新:

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

默认情况下,文件下载到$(Pipeline.Workspace)/{artifact},其中 artifact 是工件的名称。始终保留工件的文件夹结构。

您可以从上面更新的屏幕截图中看到。工件被下载到文件夹D:\a\1\MyBuildOutputs

在此处输入图像描述

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

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

于 2020-06-10T03:30:27.380 回答