Home > Software engineering >  cannot find sqlpackage in Azure pipelines Microsoft hosted agent
cannot find sqlpackage in Azure pipelines Microsoft hosted agent

Time:06-23

I want to use sqlpackage in a Powershell task within an Azure pipeline. I'm using a Microsoft hosted windows-2022 agent.

When I run sqlpackage inside the Powershell task I get:

sqlpackage : The term 'sqlpackage' is not recognized as the name of a cmdlet, function, script file, or operable program

According to the Microsoft documentation, sqlpackage is included in the Microsoft-hosted Windows agents but I can't figure out where is sqlpackage located in the agent.

I tried running this script to determine the sqlpackage version from the Microsoft documentation but it doesn't work:

- script: sqlpackage.exe /version
  workingDirectory: C:\Program Files\Microsoft SQL Server\160\DAC\bin\
  displayName: 'get sqlpackage version'

And I tried a different file path that a StackOverflow post used and it didn't work either:

- script: sqlpackage.exe /version
  workingDirectory: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\150\
  displayName: 'get sqlpackage version'

Both instances I received a not found workingDirectory error.

How do I access sqlpackage and other tools that come pre-installed on Microsoft-hosted agents?

CodePudding user response:

When you use Windows-2022 agent, the sqlpackage.exe indeed locate in the path: C:\Program Files\Microsoft SQL Server\160\DAC\bin\

If you are using PowerShell task, you need to run the following script to use the sqlpackage.exe: .\SqlPackage.exe argument

- powershell: '.\SqlPackage.exe  /version'
  workingDirectory: 'C:\Program Files\Microsoft SQL Server\160\DAC\bin\'
  displayName: 'PowerShell Script'

The script in the doc:Azure Pipelines are for the Command Line task in Azure Pipeline.

  • Related