title: How can I save google cloud build step text output to file
body: <p>I'm trying to use google cloud build. At one step, I need to get a list of all running compute instances.</p>
  
  <pre><code>- name: gcr.io/cloud-builders/gcloud
    args: ['compute', 'instances', 'list']
  </code></pre>
  
  <p>and it works fine. Problem starts when I tried to save the output to a file</p>
  
  <hr>
  
  <p><strong>Trial 1</strong>: failed</p>
  
  <pre><code>- name: gcr.io/cloud-builders/gcloud
    args: ['compute', 'instances', 'list', '&gt; gce-list.txt']
  </code></pre>
  
  <hr>
  
  <p><strong>Trial 2</strong>: failed</p>
  
  <pre><code>- name: gcr.io/cloud-builders/gcloud
    args: ['compute', 'instances', 'list', '&gt;', 'gce-list.txt']
  </code></pre>
  
  <hr>
  
  <p><strong>Trial 3</strong>: failed</p>
  
  <pre><code>- name: gcr.io/cloud-builders/gcloud
    args: &gt;
        compute instances list &gt; gce-list.txt
  </code></pre>
  
  <hr>
  
  <p><strong>Trial 4</strong>: failed</p>
  
  <pre><code>- name: gcr.io/cloud-builders/gcloud
    args: |
        compute instances list &gt; gce-list.txt
  </code></pre>
  
  <hr>
  
  <p><strong>UPDATE: 2018-09-04 17:50</strong></p>
  
  <p><strong>Trial 5</strong>: failed</p>
  
  <ol>
  <li>Build an gcloud image based on ubuntu</li>
  <li>Used that image to run custom script file 'list-gce.sh'</li>
  <li>list-gce.sh calls <code>gcloud compute instances list</code></li>
  </ol>
  
  <p>For more details you can check this gist: 
  <a href="https://gist.github.com/mahmoud-samy/e67f141e8b5d553de68a58a30a432ed2" rel="noreferrer">https://gist.github.com/mahmoud-samy/e67f141e8b5d553de68a58a30a432ed2</a></p>
  
  <p>Unfortunately I got this strange error:</p>
  
  <p>rev 1</p>
  
  <blockquote>
    <p>ERROR: (gcloud) unrecognized arguments: list (did you mean 'list'?)</p>
  </blockquote>
  
  <p>rev 2</p>
  
  <blockquote>
    <p>ERROR: (gcloud) unrecognized arguments: --version  (did you mean '--version'?)</p>
  </blockquote>
  
  <p>Any suggestions, or references?</p>