7

We are using Jenkins to build and push data to Google Cloud Storage.

We have a single build machine; and multiple different Google Projects (testing; production)

If there are parallel builds being done by the 'jenkins' user on 1 build node; is there any way to pass parameters to gcloud docker -- push so that separate credentials authenticate one push to the testing Google Project and the other to the production project?

1 Answer 1

7

There are a few options here, from a Cloud SDK standpoint.

The first one is to use different configuration directories. By default, the Cloud SDK uses ~/.config/gcloud as its configuration directory; the $CLOUDSDK_CONFIG environment variable overrides this. It's effectively the same as having two different installs if you use different configuration directories, and you don't run any risk of e.g. race conditions.

The second one is to use named configurations. This is probably easiest to illustrate with an example:

$ gcloud config configurations create foo  # creates and activates a new configuration
$ gcloud auth login  # you may want to use `activate-service-account` for non-interactive use
$ gcloud config set project foo-project
$ gcloud config configurations create bar
$ gcloud auth login
$ gcloud config set project bar-project
$ CLOUDSDK_ACTIVE_CONFIG_NAME=foo gcloud version &
$ CLOUDSDK_ACTIVE_CONFIG_NAME=bar gcloud version &

If you just want to change on configuration property, you can do so via the environment variable $CLOUDSDK_<SECTION>_<PROPERTY>. For instance, $CLOUDSDK_CORE_ACCOUNT or $CLOUDSDK_CORE_PROJECT. For some common flags, you can set them on every gcloud command: --project or --account, for instance. See gcloud help for an overview of these common flags.

That said, with gcloud docker you'll probably run into an issue in any of these cases, since docker shares one configuration file. Your best bet is probably to use docker-credential-gcr with different $GOOGLE_APPLICATION_CREDENTIALS files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.