Add multiple commands in cronjob.yaml

6/26/2019

I want to run two commands in my cronjob.yaml one after each other. The first command runs a python-scipt and the second changes an environment variable in another pod. The commands added separately work.

This is what I'm trying right now (found the syntax in How to set multiple commands in one yaml file with Kubernetes? ) but it gives me an error.

command:
- "/bin/bash"
- "-c"
args: ["python3 recalc.py && kubectl set env deployment recommender --env="LAST_MANUAL_RESTART=$(date)" --namespace=default"]

The error I get in cloudbuild:

error converting YAML to JSON: yaml: line 30: did not find expected ',' or ']'

(for the long line)

-- flo3719
google-kubernetes-engine
kubernetes

1 Answer

6/26/2019

You have nested double quotes, try something more like this:

command:
- /bin/bash
- -c
- python3 recalc.py && kubectl set env deployment recommender --env="LAST_MANUAL_RESTART=$(date)" --namespace=default

i.e. without the outer double quotes.

-- coderanger
Source: StackOverflow