简体   繁体   中英

Jenkins Execute Windows batch command fails for file change

I am trying to change text in a config file using Jenkins Windows batch command but its giving the following error.

(Get-Content config_qa.properties )  | {$_ -replace "test123", "test"}   | Set-Content config_qa.properties 

Ran the above in jenkins windows batch command. below is the error message.

'{$_' is not recognized as an internal or external command,
operable program or batch file.
Build step 'Execute Windows batch command' marked build as failure
[workspace] $ cmd /c call C:\windows\TEMP\hudson2235664364282200461.bat

Thanks

Are you sure you didn't miss WHERE operator (after first pipe)? Like:

(Get-Content config_qa.properties ) | where {$_ -replace "test123", "test"} | Set-Content config_qa.properties

EDIT: Also, you need to make sure that Jenkins is trying to run this in PowerShell, not Windows batch (default)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM