<p>I have a simple <code>cloudbuild.yaml</code> file which runs a Bazel command. This command returns a Kubernetes configuration in form as a log output.</p>

<p>My goal is to take the output of the first step and apply it to my Kubernetes cluster.</p>

<pre><code>steps:
  - name: gcr.io/cloud-builders/bazel
    args: ["run", "//:kubernetes"]

  - name: "gcr.io/cloud-builders/kubectl"
    args: ["apply", "&lt;log output of previous step&gt;"]
    env:
      - "CLOUDSDK_COMPUTE_ZONE=europe-west3-a"
      - "CLOUDSDK_CONTAINER_CLUSTER=cents-ideas"
</code></pre>

<h1>Update</h1>

<p>I've tried the following:</p>

<pre><code>- name: gcr.io/cloud-builders/bazel
  entrypoint: /bin/bash
  args:
    [
      "bazel",
      "run",
      "//:kubernetes",
      " &gt; kubernetes.yaml",
    ]

- name: "gcr.io/cloud-builders/kubectl"
  args: ["apply", "-f", "kubernetes.yaml"]
  env:
    - "CLOUDSDK_COMPUTE_ZONE=europe-west3-a"
    - "CLOUDSDK_CONTAINER_CLUSTER=cents-ideas"
</code></pre>

<p>But then I get this error:</p>

<pre><code>Running: kubectl apply -f kubernetes.yaml
error: the path "kubernetes.yaml" does not exist
</code></pre>

<p>Here's how to mount the volume:</p>

<p><a href="https://cloud.google.com/cloud-build/docs/build-config#volumes" rel="nofollow noreferrer">https://cloud.google.com/cloud-build/docs/build-config#volumes</a></p>

<p>Basically add:</p>

<pre><code>  volumes:
  - name: 'vol1'
    path: '/persistent_volume'
</code></pre>

<p>Then reference full path <code>/persistent_volume/filename/</code> when writing / reading to your file.</p>
