Windows上的GCLoud Auth Action-Service-Service-Account为什么不在Wind



我有一个Google Cloud Service帐户令牌,新下载。我想作为CI管道的一部分在Windows,Mac和Linux上激活它。为此,我这样做:

gcloud auth activate-service-account --key-file=./token.json

这在Linux和Mac上都很好。在Winddows上,我会收到以下错误:

ERROR: (gcloud.auth.activate-service-account) Could not read json file C:Usersappveyortoken.json: No JSON object could be decoded

无论我是从powershell调用 gcloud还是从cmd.exe调用 CC_1的错误。发生了什么事?

发现这是一个字符编码问题。我以前使用

将字符串进入appveyor
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($env:GCLOUD_TOKEN)) | Out-File .token.json

将文件写入UTF-16LE。Gcloud的捆绑python不在乎。我的下一次尝试使用了Set-Content -Encoding utf8 .token.json,但这是用BOM写入UTF-8的,Gcloud仍然无法处理。终于让它与以下内容一起工作:

$content = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($env:GCLOUD_TOKEN)) ; $Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False ; [System.IO.File]::WriteAllLines('token.json', $content, $Utf8NoBomEncoding)

相关内容

最新更新