我在 yaml 中使用了 azure devops :
- 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'
我需要能够获取存储在变量中的 t-sql 命令的输出,以便稍后在管道中使用它。任何想法如何获取此输出并将其存储在变量中。
我通常会使用 powershell 命令来设置环境变量,但显然这不能在此任务中完成。
任何想法都会很棒。
最佳答案
我已经解决了这个问题。因此,我可以在 Azure Devops 中使用 powershell 脚本,这样我就可以直接获取变量,然后使用 setvariable 任务将输出分配为 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"
关于sql - 从 Azure SQL InlineSqlTask 任务创建输出变量 azure devops,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71680561/