Answer a question

I have a simple jq command & it works when I run it in Powershell at a local computer. The binary file does not change.

jq 'query.....' $srcJson > $destinationJson

When Jenkins run the command above (located in a Powershell file) at a separate Windows computer, the $destinationJson binary file has changed.

For example:

enter image description here

bad-swagger.json file is created in Jenkins.

swagger.json file is created in local PowerShell windows.

Both text files have the same content but the file size is different by twice & the giff diff reveals that the binary file is different.

How to write in-place or save the new jq output to a json file without changing its binary file using Powershell?

Thank you.

Answers

The difference in output you're seeing is likely due to the fact that the file output redirection operation (>) in Windows PowerShell defaults to UTF16LE (or in Windows-speak "Unicode") encoding.

Instead of using >, try piping the output from jq to a cmdlet that allows you to explicitly set the output encoding, like Out-File:

jq 'query...' $srcJson |Out-File $destinationJson -Encoding UTF8
Logo

CI/CD社区为您提供最前沿的新闻资讯和知识内容

更多推荐