azure-devopsazure-pipelinesdacpac

Azure SQL - DacPac Deployment


I am currently trying to test my DacPac deplyoment pipelines. However, I get error message all the time:

##[error]No files were found to deploy with search pattern C:\agent\_work\5\a\sqlproj_artifacts_1\DWH\DWH\bin\Release\database.dacpacCheck out how to troubleshoot failures at

I can't find what the problem is. Here the code, idea why it does not work? Have done before and worked perfectly....

    steps:
      - task: VSBuild@1
        inputs:
          solution: '$(solution)'
          platform: '$(buildPlatform)'
          configuration: '$(buildConfiguration)'
      - task: PublishBuildArtifacts@1
        inputs:
          PathtoPublish: '$(Build.SourcesDirectory)'
          ArtifactName: 'sqlproj_artifacts_$(System.JobAttempt)'
          publishLocation: 'Container'
    steps:
    - task: DownloadBuildArtifacts@0
      inputs:
        buildType: 'current'
        downloadType: 'single'
        artifactName: 'sqlproj_artifacts_$(System.JobAttempt)'
        downloadPath: '$(System.ArtifactsDirectory)'
        deployType: 'DacpacTask'
        DeploymentAction: 'Publish'
        DacpacFile: '$(System.ArtifactsDirectory)/sqlproj_artifacts_$(System.JobAttempt)/DWH/DWH/bin/Release/$(azureSqlDBName).dacpac'

I'm using AuthenticationType: 'server'

And this is the local path where project is: source\repos\DataWarehouse\DWH\DWH

Tried to adjust the path, but it still doesn't work.

Hope you can help me, thanks!


Solution

  • You can check the path of the artifact you are looking for on the build screen when you click on artifacts:

    enter image description here

    Here the $(azureSqlDBName).dacpac file name looks suspicious to me, as in if the dacpac is produced from a sql project, then probably the file will have the project name, not the azure sql db name.

    In addition to this, I also would try to publish separate build artifacts for separate deployment, so instead of creating an artifact for the whole source artifact directory, I would copy the dacpac from the source to staging directory and then publish the dacpac artifact:

    - task: CopyFiles@2
      displayName: 'Copy DacPac Files'
      inputs:
        SourceFolder: '$(Build.SourcesDirectory)'
        Contents: '**/*.dacpac'
        TargetFolder: '$(Build.ArtifactStagingDirectory)/db'
        CleanTargetFolder: true
        OverWrite: true
        flattenFolders: true
    
    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)/db'
        ArtifactName: 'sqlproj_artifacts_$(System.JobAttempt)'
        publishLocation: 'Container'
    

    Then it is easier to find what you are looking for when you need to use the artifact. Please note the flattenFolders flag which comes in handy when you are dealing with a single package within the artifact.

    One more thing is the use of pipeline artifacts instead of build artifacts, since you are already working with yaml pipelines, and possibly multi-stage yamls, you can utilize pipeline artifacts which are automatically downloaded to the default workspace folder.

    Hope it helps,