Gitlab ci/cd job showing error (Could not read json file) when I'm tring to setup gcp service account

Viewed 1675
$ echo $SERVICE_ACCOUNT_DEV > ${HOME}/gcloud-service-key.json
$ gcloud auth activate-service-account --key-file ${HOME}/gcloud-service-key.json
ERROR: (gcloud.auth.activate-service-account) Could not read json file /root/gcloud-service-key.json: Expecting value: line 2 column 1 (char 1).

I checked the SERVICE_ACCOUNT_DEV json file stored in gitlab ci/cd variable but there is no issue with it.

1 Answers

Have a look at the documentation Protected branches and GitLab CI/CD environment variables. Variables can be protected. Whenever a variable is protected, it would only be securely passed to pipelines running on the protected branches or protected tags. The other pipelines would not get any protected variables. So, if the you have a protected variables then it will be only available for protected branches.

As it was confirmed at the comment section, making the branch and variable protected solved the issue.

Related