在下面的任务中,我在运行 yaml 代码时可能会出现错误,如下所示,
我的yaml代码:
- task: PowerShell@2
displayName: Clean some space
inputs:
targetType: inline
script: "Write-Host \"Hello World\"\n\nWrite-Host \"Number of files\"\n(Get-ChildItem . -Recurse -ErrorAction SilentlyContinue | Measure-Object).Count\nWrite-Host \"Size\"\n(Get-ChildItem . -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum / 1Gb\n\n$fol1 = Join-Path $(System.DefaultWorkingDirectory)/bapiweb-PowerBI\"tests\"\n$fol2 = Join-Path $(System.DefaultWorkingDirectory)/bapiweb-PowerBI\"VisualRegressionTesting\"\n$fol3 = Join-Path $(System.DefaultWorkingDirectory)/bapiweb-PowerBI\"buildArtifacts\"\n$fol4 = Join-Path $(System.DefaultWorkingDirectory) \"code\\powerbi\\bapiweb-PowerBI\"\n$fol5 = Join-Path $(System.DefaultWorkingDirectory) \"bapiweb-PowerBI\\BAPIShared\\Services\"\n\nWrite-Host \"Deleting folder \" $fol1 \nRemove-Item -Path $fol1 -Recurse -Force\nWrite-Host \"Deleting folder \" $fol2 \nRemove-Item -Path $fol2 -Recurse -Force\nWrite-Host \"Deleting folder \" $fol3 \nRemove-Item -Path $fol3 -Recurse -Force\nWrite-Host \"Deleting folder \" $fol4 \nRemove-Item -Path $fol4 -Recurse -Force\nWrite-Host \"Deleting folder \" $fol5\nRemove-Item -Path $fol5 -Recurse -Force\n\nWrite-Host \"Number of files\"\n(Get-ChildItem . -Recurse -ErrorAction SilentlyContinue | Measure-Object).Count\nWrite-Host \"Size\"\n(Get-ChildItem . -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum / 1Gb\n\nWrite-Host \"Bye world\""
我遇到的错误
Join-Path : Cannot process command because of one or more missing mandatory
parameters: ChildPath.
At C:\__w\_temp\374b657d-7929-4065-b02f-c4ca812bded5.ps1:11 char:9
+ $fol1 = Join-Path C:\__w\1\s/bapiweb-PowerBI"tests"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Join-Path], ParentContains
ErrorRecordException
+ FullyQualifiedErrorId : MissingMandatoryParameter,Microsoft.PowerShell.C
ommands.JoinPathCommand
##[error]PowerShell exited with code '1'.
当我打印测试路径的位置时,我可以看到如下所示以及我在 yaml 代码中更新的内容。
C:\__w\1\s\bapiweb-PowerBI\tests
我尝试了很多方法,但还是坚持这个。请帮我解封。
您缺少 3 个空格:
$fol1 = Join-Path $(System.DefaultWorkingDirectory)/bapiweb-PowerBI\"tests\"
$fol2 = Join-Path $(System.DefaultWorkingDirectory)/bapiweb-PowerBI\"VisualRegressionTesting\"
$fol3 = Join-Path $(System.DefaultWorkingDirectory)/bapiweb-PowerBI\"buildArtifacts\"
另请参阅 @Rui Jarimba 的建议和链接,以使 YAML 代码更易于阅读(从而调试)