Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass parameters to Google Cloud Run Job

I have ran this example using this job

Everything worked well.

Now I am trying to see if there is a way to pass parameters to jobs running on Cloud Run.

I understand I can use the command to create jobs with a --message-body argument like this:

 gcloud scheduler jobs create http JOB_NAME \
  --location REGION \
  --schedule="*/3 * * * *" \
  --uri="https://REGION-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/PROJECT_ID/jobs/CLOUD_RUN_JOB_NAME:run" \
  --http-method POST \
  --oauth-service-account-email  [email protected]
  --message-body="This is the body"

However while checking the documentation for Cloud Run jobs here.

I don't see parameters being mentioned anywhere. The idea is that depending on a JSON that contains the parameters we can run different kind of jobs (it's a same job that changes its operation based on the parameters)

like image 201
carlos palma Avatar asked Dec 06 '25 10:12

carlos palma


1 Answers

This is now possible using the REST API for Cloud Run Jobs.

  • The REST API allows passing in a request body
  • The request body accepts an override defnition
  • To make the call, you'll need to get the token of the current executing identity

A full working repo of how to do this is here: https://github.com/CharlieDigital/gcr-invoke-job-overrides

A more in depth writeup here: https://medium.com/@chrlschn/programmatically-invoke-cloud-run-jobs-with-runtime-overrides-4de96cbd158c

The sample is in C#/.NET, but it's easy enough to translate to any other language.

Here's the log output of the environment variables and entry point args:

Cloud Run Job log showing the custom environment variables and entry point arguments

like image 62
Charles Chen Avatar answered Dec 10 '25 09:12

Charles Chen