0

This is my jenkins script. Without pipeline, can see ls result list. but when include pipeline with foreach, assign null to '$_'. Why??

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

error log

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

1 Answers1

1

Try changing syntax to foreach-object

 powershell "ls ${srcPath}\\*.py -Recurse | %{rm $_}"

further reading:
Difference between ForEach and ForEach-Object in powershell

TheGameiswar
  • 27,855
  • 8
  • 56
  • 94