Setting env var in commands

I am trying this:

  commands:
    - MYVAR=$(my_command)
    - echo $MYVAR

It looks like $MYVAR is undefined. Is that expected behavior? How would I go about fixing that? I only the variable to be set for the rest of the step, not the entire pipeline.