creating an output variable azure devops from the Azure SQL InlineSqlTask task

0 votes

 YAML content :

- task: SqlAzureDacpacDeployment@1
  displayName: 'Azure SQL InlineSqlTask'
  inputs:
    azureSubscription: 'Service Connection'
    AuthenticationType: servicePrincipal
    ServerName: 'xxx.database.windows.net'
    DatabaseName: 'xxx-Dev'
    deployType: InlineSqlTask
    SqlInline: |
     select name as username,
                  create_date,
                  modify_date,
                  type_desc,
                  authentication_type_desc as authentication_type
                  from sys.database_principals where type_desc = 'EXTERNAL_USER'

I want to have the output of this t-SQL command stored in a variable. Can someone tell me how to do it?

Apr 21, 2022 in Other DevOps Questions by Kichu
• 19,040 points
947 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Use a PowerShell script within Azure DevOps so you can directly get the variable and then use the set variable task to assign the output as an env: variable.

$query = "select name as username,

             create_date,

             modify_date,

             type_desc,

             authentication_type_desc as authentication_type

             from sys.database_principals where type_desc = 'EXTERNAL_USER'"


$clientid = "guid"

$tenantid = "guid"

$secret = "guid"

$request = Invoke-RestMethod -Method POST `

           -Uri "https://login.microsoftonline.com/$tenantid/oauth2/token"`

           -Body @{ resource="https://database.windows.net/"; grant_type="client_credentials"; client_id=$clientid; client_secret=$secret }`

           -ContentType "application/x-www-form-urlencoded"

$access_token = $request.access_token


$sqloutput = Invoke-Sqlcmd -ServerInstance $.database.windows.net -Database db$ -AccessToken $access_token -query $query


Write-Host "##vso[task.setvariable variable=GetVar;]$sqloutput"

I hope this helps.

answered Apr 22, 2022 by narikkadan
• 63,600 points

edited Mar 5

Related Questions In Other DevOps Questions

0 votes
1 answer

Azure DevOps yaml passing variable using "##vso[task.setvariable" not working

You can stop the pipeline from running ...READ MORE

answered Feb 8, 2022 in Other DevOps Questions by Bhavitha
• 1,000 points
2,017 views
0 votes
0 answers

How do I add the azure-devops commands to the Azure CLI in an offline on-premise server?

I wanted to add the azure-DevOps extension to the Azure ...READ MORE

Apr 19, 2022 in Other DevOps Questions by Kichu
• 19,040 points
766 views
0 votes
0 answers

Multiple YAML build pipelines in Azure DevOps

Using the new YAML way I want ...READ MORE

Mar 15, 2022 in DevOps Tools by Kichu
• 19,040 points
1,280 views
0 votes
0 answers
0 votes
0 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP