我被指示“以编程方式处理”,而且我无法更改或添加凭据文件。
使用Github Actions,我创建了需要对GCloud进行身份验证的工作流。不幸的是,似乎变量是在执行run
命令之前被替换的,从而导致产生多行错误的多行YAML文件。
这是YAML的摘要:
# Setup gcloud CLI
- name: Use Google Cloud Platform
uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '270.0.0'
service_account_email: ${{ secrets.SA_EMAIL }}
service_account_key: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
- run: cd ui/ && pwd && npm install && npm run test
env:
CI: true
- run: |
echo ${{ secrets.GCP_AUTH_STAGING }} | gcloud auth activate-service-account --key-file=-
gcloud container clusters get-credentials staging --region northamerica-northeast1 --project example-staging
cd ui/ && pwd && npm run build && cd build/ && gsutil cp -r . gs://test.example.com/
我尝试使用CREDS=$( ${{ secrets.GCP_AUTH_STAGING }} )
之类的字符来转义凭证,但这只会导致另一个多行问题。我相信YAML变量会在执行前被替换,而不是作为环境传递。
如果有人有命令行解决方案,将不胜感激!
请注意,我知道YAML中也有一个服务帐户/密钥,但是我无法访问它。
答案 0 :(得分:0)
使用base 64,我们将服务帐户JSON编码并通过环境变量将其传递。然后,在使用外壳程序脚本调用activate-service-account
解码之前。
示例代码:
echo "$GCP_CREDENTIALS" > gcp_credentials_enc.json
cat gcp_credentials_enc.json | base64 -d > gcp_credentials.json