Reputation: 21
I want to set the project id in environment variable so that I don't want to write again and again
kindly help me how to do in google cloud SDK
when i use this command "export GOOGLE_CLOUD_PROJECT=$(gcloud config get-value core/project)"
it gives me error 'export' is not recognized as an internal or external command, operable program or batch file.
Upvotes: 2
Views: 10127
Reputation: 81336
You are trying to execute a Linux command on Windows.
The equivalent for Windows executed from a batch file is:
gcloud config get-value core/project > project.tmp
for /f "delims=" %%x in (project.tmp) do set GOOGLE_CLOUD_PROJECT=%%x
del project.tmp
Put those lines in a batch file (*.bat). The reason is the %%
escaping. If you hand type into the Command Prompt use the following example. Notice the change from %%
to %
.
The equivalent for Windows typed at a Comman Prompt:
gcloud config get-value core/project > project.tmp
for /f "delims=" %x in (project.tmp) do set GOOGLE_CLOUD_PROJECT=%x
del project.tmp
The command gcloud config get-value core/project
outputs more than one line of text. This is the reason for the for
loop. The for loop will read each line from project.tmp
and assign the value to GOOGLE_CLOUD_PROJECT. The last set value is the PROJECT ID.
If you use this example in a batch script, then add the keyword call
in front of gcloud
. The reason is that gcloud
is a script itself and when it returns without the call
, your script will exit.
call gcloud config get-value core/project > project.tmp
Windows legacy (antique) syntax can be a pain at times.
Upvotes: 2
Reputation: 40051
See @saigeetha-sundar correct reply.
However, it appears that you have set the Project ID using gcloud config set core/project
. The intent of the gcloud config set
command is to set default values for gcloud
properties so that you do not need to write them repeatedly (as you wish).
Just to be clear:
If the core/project
value is unset...
gcloud config unset core/project
If you don't specify --project=[[YOUR-PROJECT]]
on commands that expect it, you'll get errors...
NOTE I'm using
gcloud iam service-accounts list
as an example.
gcloud iam service-accounts list
ERROR: The required property [project] is not currently set.
You may set it for your current workspace by running:
$ gcloud config set project VALUE
or it can be set temporarily by the environment variable [CLOUDSDK_CORE_PROJECT]
And you must always specify it, e.g.:
gcloud iam service-accounts list --project=[[YOUR-PROJECT]]
DISPLAY NAME EMAIL
Default compute service account [email protected]
But, if you set the configuration value:
gcloud config set core/project [[YOUR-PROJECT]]
Then any command that requires the project value will work without specifying it:
gcloud iam service-accounts list
DISPLAY NAME EMAIL
Default compute service account [email protected]
Upvotes: 1
Reputation: 144
I tried running the command from my project, the command is running successfully in Google Cloud shell, but the error seems to be Windows command line error, if you are using windows to run the command you would have to ,use the "Set" command to create variables.
Upvotes: 0