Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute SQLCMD.exe from PowerShell in an Azure DevOps Release Pipeline

I'm porting our deployment infrastructure to Azure DevOps (formerly Visual Studio Team Services), but I've run into an issue I can't find any good solutions to.

We're using EF Core Migrations, and to work around some unrelated issues we need to dynamically wrap SQL scripts in SQLCmd, which is easy using PowerShell.

However, when executing our script as a regular PowerShell step in the release pipeline, it fails because SQLCMD.exe is not available. Not so surprising - but I also can't find any documented way of installing it.

Is there a tool installer or some similar ready-made component that will let me execute a PowerShell script that calls out to SQLCMD.exe (via Invoke-SqlCmd) as part of an Azure Devops Pipeline? If not, what's the easiest way to accomplish this anyway?

like image 675
Tomas Aschan Avatar asked Oct 15 '18 18:10

Tomas Aschan


People also ask

How do I trigger Azure DevOps Pipeline from PowerShell?

Execute Powershell script Azure_Trigger_Release. ps1 to trigger an Azure DevOps release pipeline(##create-a-release-pipeline). This job is executed based on the condition, that the job checkQualityGate failed, and will regress the ISPW assigment.


1 Answers

Haven't tried this myself, but are you allowed to install Powershell modules for the current user on a hosted agent? Because Invoke-SqlCmd is part of the SqlServer module, which can be installed from the Powershell gallery with:

Install-Module -Name SqlServer -Scope CurrentUser
like image 146
Leon Bouquiet Avatar answered Nov 15 '22 05:11

Leon Bouquiet