0

Using TFS 2018. I have setup a build pipeline that builds my solution and executes all unit tests. I want to add a step on the end that queries a table in SQL Server and returns back a boolean value, if false, I would like to fail the pipeline and return an error.

I have seen many extensions that allow me to execute a script, but none that return data I can use to perform an action.

Is this possible?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

You can use sqlcmd.exe from a Commandline/PowerShell Task to execute a query, then process the output in whatever way you want.

Similarly you can use the standard .NET SqlConnection/SqlCommand classes in PowerShell to execute a query and interpret the result. As well as the Invoke-Sqlcmd function.

To pass or fail the build you can use the Azure Pipeline Log commands to pass status back to the agent.

In Batch:

echo ##vso[task.complete result=Failed;]Your Message Here

Or in PowerShell:

Write-Output "##vso[task.complete result=Failed;]Your Message Here"
jessehouwing
  • 106,458
  • 22
  • 256
  • 341