在jenkins(windows)中,powershell ls管道获取null

在jenkins(windows)中,powershell ls管道获取null,powershell,jenkins,groovy,Powershell,Jenkins,Groovy,这是我的詹金斯剧本。 如果没有管道,可以查看ls结果列表。 但是,当包含foreach的管道时,将null分配给“$\ux”。为什么 stage('Module Build'){ gitlabCommitStatus('Module Build'){ powershell "${pythonPath} -m compileall ${srcPath}" powershell "ls ${srcPath}\\*.py -Recu

这是我的詹金斯剧本。 如果没有管道,可以查看ls结果列表。 但是,当包含foreach的管道时,将null分配给“$\ux”。为什么

stage('Module Build'){
    gitlabCommitStatus('Module Build'){
        powershell "${pythonPath} -m compileall ${srcPath}"
        powershell "ls ${srcPath}\\*.py -Recurse | foreach {rm $_}"
    }
}
错误日志

d:\...\durable-51664e76\powershellScript.ps1:1 char:33
+ ls src\*.py -Recurse | foreach {rm "null"}

+                                 ~~~~~~~~~

    + CategoryInfo          : ObjectNotFound: (D:\Jenkins\work...istributor\nu 

   ll:String) [Remove-Item], ItemNotFoundException

    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.Remov 

   eItemCommand


尝试更改foreach对象的语法

 powershell "ls ${srcPath}\\*.py -Recurse | %{rm $_}"
进一步阅读: