<p>I am working with an Argo workflow.</p>
<p>There is a DAG step in my <code>entrypoint</code> which follows several normal steps. One of these steps does a <code>sys.stdout</code>. Once inside of the DAG step, I want some of the tasks to reference the results from the <code>sys.stdout</code>.</p>
<p>I know if we wanted to reference the <code>sys.stdout</code> when the workflow just goes from one step to the next (without the DAG), we can do <code>{{steps.step-name.outputs.result}}</code>. The same does not work inside of a DAG task though.</p>
<p>How can I reference the sys.stdout inside of a DAG task so I can use it with <code>withParam</code>?</p>
<p><strong>Edit:</strong></p>
<p>The workflow looks like the following:</p>
<pre><code>  templates:
  - name: the-entrypoint
    steps:
    - - name: step01
        template: first-step
    - - name: step02
        template: second-step
    - - name: step03
        template: third-step
    - - name: step04-the-dag-step
        template: fourth-step
</code></pre>
<p>In general, if <code>third-step</code> does a <code>sys.stdout</code>, we can reference it by <code>{{steps.step03.outputs.result}}</code> in <code>fourth-step</code>. However, in this case <code>fourth-step</code> is a DAG, and if one of the DAG tasks wants to use the <code>sys.stdout</code>, calling <code>{{steps.step03.outputs.result}}</code> as an argument/parameter inside of DAG tasks throws up an error.</p>
<p>The question is then how can one correctly reference the <code>sys.stdout</code> generated by <code>third-step</code> inside <code>fourth-step</code> DAG tasks?</p>

<h1>A bit of background about template outputs</h1>
<p>Argo Workflows supports a number of different <a href="https://github.com/argoproj/argo-workflows/blob/master/docs/workflow-concepts.md#template-types" rel="noreferrer"><em>types of templates</em></a>.</p>
<p>Each type of template supports different types of reference <em>within the template</em>.</p>
<p><strong>Within a <code>steps</code> template</strong>, you may access the output parameters of other steps with <code>steps.step-name.outputs.parameters.param-name</code> (for named parameters) or <code>steps.step-name.outputs.result</code> (for the stdout of a <code>script</code> or <code>container</code> template).</p>
<p>Example (<a href="https://github.com/argoproj/argo-workflows/blob/master/examples/output-parameter.yaml" rel="noreferrer">see full Workflow</a>):</p>
<pre class="lang-yaml prettyprint-override"><code>  - name: output-parameter
    steps:
    - - name: generate-parameter
        template: whalesay
    - - name: consume-parameter
        template: print-message
        arguments:
          parameters:
          - name: message
            value: &quot;{{steps.generate-parameter.outputs.parameters.hello-param}}&quot;
</code></pre>
<p><strong>Within a <code>dag</code> template</strong>, you may access the output of various tasks using a similar syntax, just using <code>tasks.</code> instead of <code>steps.</code>.</p>
<p>Example (<a href="https://github.com/argoproj/argo-workflows/blob/master/examples/dag-conditional-parameters.yaml" rel="noreferrer">see full Workflow</a>):</p>
<pre class="lang-yaml prettyprint-override"><code>    - name: main
      dag:
        tasks:
          - name: flip-coin
            template: flip-coin
          - name: heads
            depends: flip-coin
            template: heads
            when: &quot;{{tasks.flip-coin.outputs.result}} == heads&quot;
          - name: tails
            depends: flip-coin
            template: tails
            when: &quot;{{tasks.flip-coin.outputs.result}} == tails&quot;
</code></pre>
<p><strong>Within a <code>container</code> or <code>script</code> template</strong>, you may access <em>only the inputs of that template</em>*. You may not directly access the outputs of steps or tasks from steps or tasks templates from a container or script template.</p>
<h1>Referencing a step output from a DAG</h1>
<p>As mentioned above, a DAG template cannot directly reference step outputs from a <code>steps</code> template. But a step within a <code>steps</code> template can <em>pass a step output to a DAG template</em>.</p>
<p>In your example, it would look something like this:</p>
<pre class="lang-yaml prettyprint-override"><code>  templates:
  - name: the-entrypoint
    steps:
    - - name: step01
        template: first-step
    - - name: step02
        template: second-step
    - - name: step03
        template: third-step
    - - name: step04-the-dag-step
        template: fourth-step
        arguments:
          parameters:
          - name: some-param
            value: &quot;{{steps.step03.outputs.result}}&quot;
  - name: fourth-step
    inputs:
      parameters:
      - name: some-param
    dag:
      tasks:
        # use the input parameter in the fourth-step template with &quot;{{inputs.parameters.some-param}}&quot;
</code></pre>
<h1>tl;dr</h1>
<p><code>steps.</code> and <code>tasks.</code> variables are meant to be <em>referenced within a single steps- or tasks-template</em>, but they can be explicitly <em>passed between templates</em>. If you need to use the output of a step in a DAG, directly pass that output as an argument where the DAG is invoked.</p>
<p>In your case, the DAG template is invoked as the last of four steps, so that is where you will pass the argument.</p>
<p><sub>* Okay, you also have access to <a href="https://github.com/argoproj/argo-workflows/blob/master/docs/variables.md" rel="noreferrer">various other variables</a> from within a <code>script</code> or <code>container</code> template, but you don't have access to variables that are scoped as internal variables within another template.</sub></p>
