VSTS build doesn't pickup the dacpac file (hosted agent in cloud)

二次信任 提交于 2020-01-23 10:41:09

问题


I'm trying to use VSTS to deploy into my database, the problem is in one of the steps I need to pick up the dacpac file and deploy it to the Azure SQL server but it fails: in that step, I'm using "Execute Azure SQL: DacpacTask" which is provided by Microsoft in VSTS. there is a filed to do it which is called "DACPAC File" and the documentation said to use it like this:

$(agent.releaseDirectory)\AdventureWorksLT.dacpac

but it gave me the below error:

No files were found to deploy with search pattern d:\a\1\s\$(agent.releaseDirectory)\AdventureWorksLT.dacpac

so I did a cheating and put the below value in it:

d:\a\1\s\AdventureWorksLT.dacpac

it does work but obviously, it won't work forever as I need to use an environment variable, something like :

$(agent.releaseDirectory)\AdventureWorksLT.dacpac

any suggestion?


回答1:


I've had this same problem. I wasn't able to find detailed documentation, but from experimenting, this is what I found.

I'm assuming that your DACPAC is created as part of a Build Solution task. After the build completes and the DACPAC is created, it exists in a sub-folder of the $(System.DefaultWorkingDirectory) directory.

Apparently, the Azure SQL Database Deployment task cannot access the $(System.DefaultWorkingDirectory) folder. So the file must be copied somewhere where it can be accessed. So here's what I did:

  1. The Visual Studio Build task builds the solution, including the DACPAC. The resulting DACPAC is placed in a $(System.DefaultWorkingDirectory) sub-folder.
  2. Add a Copy Files task as your next step. The Source Folder property should be "$(System.DefaultWorkingDirectory)". The Contents property should be "**/YourDacPacFilename.dacpac". The Target folder should be $(build.artifactstagingdirectory). The "**/" tells VSTS to search all subfolders for matching file(s).
  3. Add an Azure SQL Database Deployment task to deploy the actual DACPAC. The DACPAC file will be in the $(build.artifactstagingdirectory).



回答2:


I had the same problem and I solved it by removing the old artifact from the release and adding it again to take the correct alias of the new artifact. That's why the Azure SQL Database Deployment task says it doesn't have access to the $(System.DefaultWorkingDirectory) folder, the artifact has changed and you must make sure you're using the new one that is saved in the azure pipeline.



来源:https://stackoverflow.com/questions/47052666/vsts-build-doesnt-pickup-the-dacpac-file-hosted-agent-in-cloud

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!