0

According to the documentation, it is possible to pass environment variables to python module using a config file with the --config argument of gcloud ai custom-jobs create.

However I'd prefer not to use a config file and use only the CLI. Is it possible to use only the CLI to pass environment variables to the packaged python code?

I am adding a base command line that I would like to expand so that it takes also environment variables to pass to the job.

gcloud ai custom-jobs create \
  --region=europe-west9 \
  --display-name=try_vai \
  --python-package-uris=gs://data-analyses/r_d/try_vertex_ai/dist/try_vertex_ai-0.1.tar.gz \
  --worker-pool-spec=machine-type=e2-standard-4,replica-count=1,executor-image-uri=europe-docker.pkg.dev/vertex-ai/training/scikit-learn-cpu.0-23:latest,python-module=src.try_vertex_ai
LucG
  • 1,238
  • 13
  • 25

1 Answers1

1

I took the sample of the gcloud CLI documentation and I combine it with the container spec description

workerPoolSpecs:
  machineSpec:
    machineType: n1-highmem-2
  replicaCount: 1
  containerSpec:
    imageUri: gcr.io/ucaip-test/ucaip-training-test
    args:
    - port=8500
    env:
    - name: envName1,
      value: envValue1
    - name: envName2,
      value: envValue2
    command:
    - start
guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
  • Thanks but this is not using the CLI. This is a configuration file to be passed with the `--config` option. As I have written in the original question, I'd prefer not to use a configuration file and only the command line interface. Or can I used the configuration file only for the environment variables? Or two configuration files? – LucG Mar 22 '23 at 13:45
  • Not sure to understand. If you don't want to use the CLI, you can use the API. But you have to provide the YAML config to set the machine, container and env defintiion – guillaume blaquiere Mar 22 '23 at 15:39
  • I want to use the CLI. It is the point. I don't want a configuration file. You provided a configuration file in your answer :) Everything that there is in the configuration file you provided can also be passed directly to the CLI. Everything except the env field, or I don't know how. – LucG Mar 22 '23 at 15:46
  • This feature may not have been implemented. If you run `gcloud ai custom-jobs create --help`, you can get a full list of what is passable. Someone asked a similar question here: https://stackoverflow.com/questions/69302528/how-to-pass-environment-variables-to-gcloud-beta-ai-custom-jobs-create-with-cust. Have you tried this with `gcloud beta`? Also, have you tried the `--args` field? It seems that it can pass args into your container. – sneekiesnek Mar 31 '23 at 10:40
  • Also, on a side note... `--config` is part of the CLI, so using a config file = using the CLI as intended. As a workaround, you could create the YAML file in bash and pass it all as one command. – sneekiesnek Mar 31 '23 at 10:40