title: How do I set an environment or substitution variable via a step in Google Cloud Build?
body: <p>Basically, when using Google Cloud Build, how do I read a value that was written in an earlier build step in subsequent steps? </p>
  
  <p>Specifically, I'd like to make a custom image tag that's based on a combination of the timestamp and $SHORT_SHA.  Something like the below. Though, it doesn't work, as docker complains about "export", and, even if that worked, it likely will be a different env:</p>
  
  <pre><code>  # Setting tag in a variable:
    - name: 'ubuntu'
      args: ['export', '_BUILD_TAG=`date', '-u', '+%Y%m%dT%H%M%S_$SHORT_SHA`']
  </code></pre>
  
  <p>Then, in a later step:</p>
  
  <pre><code>  # Using tag from the variable:
    - name: gcr.io/cloud-builders/docker
      args: ['build', '-t', 'gcr.io/$PROJECT_ID/$_BUILD_TAG', '.']
  </code></pre>
  
  <p>So, how do I use the output of one step in another?  I could write the contents of <code>date</code> to a file, and then read it, but I'm back at not knowing how to set the variable from the file I read (or otherwise interpolate its results to form the argument to docker build). </p>