<h2>Setup description</h2>

<p>I have the following scenario: Created a Build Pipeline in Azure DevOps and after setting up my Kubernetes cluster I want to get a specific pod name using kubectl. I am doing this via the "Deploy to Kubernetes" task V1, which looks like this:</p>

<pre><code>steps:
- task: Kubernetes@1

  displayName: 'Get pod name'
  inputs:
    azureSubscriptionEndpoint: 'Azure Pay-as-you-Go (anonymized)'
    azureResourceGroup: MyK8sDEV
    kubernetesCluster: myCluster
    command: get
    arguments: 'pods -l "app=hlf-ca,release=ca" -o jsonpath="{.items[0].metadata.name}"'
</code></pre>

<p>So the task is running successfully and I want to get the output string of the above command. In the Pipeline visual designer it shows me an output variable of <strong>undefined.KubectlOutput</strong> that is being written to.</p>

<h2>Problem statement</h2>

<p>I have created a subsequent Bash script task directly after the above kubectl task. If I read the variable <strong>$KUBECTLOUTPUT</strong> or <strong>$UNDEFINED_KUBECTLOUTPUT</strong> it just returns an empty string. What am I doing wrong? I just need the output from the previous command as a variable.</p>

<h2>My goal with the action</h2>

<p>I am trying to make sure that the application I deployed with a helm chart in the previous step is up and running. In the next step I need to run some scripts inside the application pods (using kubectl exec) so I want to make sure that at least 1 pod hosting the app is up and running so that I can execute commands against it. In the meantime I realized that I can skip the checking step if I use the --wait flag when deploying the helm chart, but I still have issues using kubectl from within the bash script.</p>

<p>If you give the NAME for the kubectl task eg. SomeNameForYourTask like below</p>
<pre><code>- task: Kubernetes@1
   name: SomeNameForYourTask 
   displayName: some display name
   inputs:
     connectionType: Kubernetes Service Connection
  ...
</code></pre>
<p>you will be able to access kubectl command output using</p>
<pre><code>echo $(SomeNameForYourTask.KubectlOutput)
</code></pre>
<p>or</p>
<pre><code>echo $(SomeNameForYourTask.KUBECTLOUTPUT)
</code></pre>
<p>or</p>
<pre><code>echo $SOMENAMEFORYOURTASK_KUBECTLOUTPUT
</code></pre>
<p>in the following script task(s). Of course, the output should not exceed 32766 chars (according to the code <a href="https://github.com/microsoft/azure-pipelines-tasks/blob/b0e99b6d8c7d1b8eba65d9ec08c118832a5635e3/Tasks/KubernetesV1/src/kubernetes.ts" rel="noreferrer">https://github.com/microsoft/azure-pipelines-tasks/blob/b0e99b6d8c7d1b8eba65d9ec08c118832a5635e3/Tasks/KubernetesV1/src/kubernetes.ts</a>).</p>
