我正在开发 Azure Devops 构建管道,它将使用 Power BI 部署管道自动执行 Power Bi 部署。 Yaml 文件正在执行我的 powershell 脚本,其中包含所有逻辑,最后它运行一个命令:
try{
$deployResult = Invoke-PowerBIRestMethod -Url $url -Method Post -Body $body | ConvertFrom-Json
}
catch {
$errorMsg = Resolve-PowerBIError -Last
Write-Output $errorMsg.Message
}
该命令在本地和管道中都运行良好,但问题是,当部署期间有时出现错误(通常是用户错误)时,管道中的输出仅由 1 行组成,这使得调试这些问题变得困难。 响应状态代码并不表示成功:400(错误请求)。
但是,在本地,完全相同的脚本会返回更多信息:
{
"code": "Alm_InvalidRequest_ArtifactsValidationFailure",
"pbi.error": {
"code": "Alm_InvalidRequest_ArtifactsValidationFailure",
"details": [
{
"code": "Alm_InvalidRequest_ArtifactReferenceModelWithoutPermissions",
"detail": {
"type": 1,
"value": "{\"artifactTypeName\":\"Reports\",\"artifactId\":\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"}"
}
}
],
"exceptionCulprit": 1
}
}
Yaml 文件是:
---
trigger:
branches:
include:
- INT
variables:
workspaceName: My workspace [Development]
pipelineName: My pipeline
stages:
- stage: DeployToINT
jobs:
- deployment: DeployToINT
pool:
name: POWERBI
environment: Power BI test
strategy:
runOnce:
deploy:
steps:
- task: CmdLine@2
inputs:
script: 'git config --system core.longpaths true'
- checkout: git://Power BI/_git/DevOps@test
- checkout: self
fetchDepth: 100
- task: PowerShell@2
inputs:
filePath: './DevOps/testApicall.ps1'
arguments: '-passwordKey "$(passwordKeyINT)"'
failOnStderr: true
showWarnings: true
我尝试使用退出代码和错误处理,但无论我尝试什么,仍然会产生相同的输出。 有没有办法解决 Azure DevOps 管道中的此问题?
您可以使用 Powershell 转录本并登录不同的文件,甚至可以使用内联 yaml 脚本中的文件路径代替文件路径,并将脚本写入启动转录本并调用 Powershell 文件,然后结束转录本并显示输出 有关更多详细信息,请检查此: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript?view=powershell-7.4