Override environment variables in one-off jobs

Is it possible to override env variable(s) for a one-off job? The documentation here mentions about potential override in description https://docs.render.com/jobs,

but I cannot find it documented in API spec. Create job

For what its worth, I tried passing envVars array of kv pair in addition to startCmd, but that does not seem to work. Example

curl --request POST 'https://api.render.com/v1/services/srv-xxx/jobs' \
    --header 'Authorization: Bearer xxx' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "envVars":[
          {
             "key": "HELLO",
             "value": "Does this work?"
          }
        ],
        "startCommand": "echo $HELLO"
    }'

I also tried this format of startCmd from another post in the forum, which does not work either.

curl --request POST 'https://api.render.com/v1/services/srv-xxx/jobs' \
    --header 'Authorization: Bearer xxx' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "startCommand": "sh -c export HELLO=Render; echo $HELLO"
    }'

and also tried

curl --request POST 'https://api.render.com/v1/services/srv-xxx/jobs' \
    --header 'Authorization: Bearer xxx' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "startCommand": "HELLO=Render echo $HELLO"
    }'

Appreciate any pointers.

That is an interesting find, I never knew One-off Jobs to allow for environment overrides. It won’t be possible to override it via the Start Command because that command isn’t evaluated by shells directly. No expansion, no overriding bash’isms like you tried here, etc. It’s difficult for me to explain how exactly the Start Command gets executed because quite frankly, I don’t entirely understand why it’s special in the first place.

That document should probably be updated to remove reference to environment overrides, which I’ve written up to be done. Exactly as you said, the API docs (which are generated automatically, and programmatically) are the primary reference, so if the API docs don’t state the ability to do so, I don’t believe it can be done.

I would have expected wrapping commands in sh -c to be able to perform this, I’m at a loss to explain why the execution environment is preventing this from taking place. The recommendation that we’ve given to other customers in the past is to move any expansion and other environment variable modification work into a script like build.sh or such, and then call that script. However, I can’t think of an analog to accomplish that in a One-Off Job.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.