<p>I am incorporating HPA creation based on certain toggle-able environment variables passed to our Jenkins bash deploy script.</p>
<p>There are 3 conditions:</p>
<ol>
<li>Correct HPA variables are found
<ul>
<li>run 'get hpa' in project and delete it, before re-adding incase max/min pods or cpu
thresholds have changed</li>
</ul>
</li>
<li>HPA is set to 'toggle off'
<ul>
<li>run 'get hpa' in project, and if found, delete it</li>
</ul>
</li>
<li>HPA Env Variables are not present
<ul>
<li>run 'get hpa' in project and if found, delete it</li>
</ul>
</li>
</ol>
<p>This is the actual line of bash I'm running:</p>
<p><code>hpaExists=`kubectl get hpa/${APP_NAME} --no-headers | awk '{print $1}'</code></p>
<p>The code is running fine, but if there is no hpa found, it shows this error in the console:</p>
<p><code>Error from server (NotFound): horizontalpodautoscalers.autoscaling &quot;${APP_NAME}&quot; not found</code></p>
<p>There is <em>technically</em> no issue with the error happening, but I know it will confuse developers and QA when running the Jenkins deploy jobs to see an error message and I would like to suppress it.</p>
<p>I have tried:
<code>kubectl get hpa/${APP_NAME} --no-headers | awk '{print $1}' &gt; /dev/null</code></p>
<p><code>kubectl get hpa/${APP_NAME} --no-headers | awk '{print $1}' &gt; /dev/null 2&gt;&amp;1</code></p>
<p><code>kubectl get hpa/${APP_NAME} --no-headers | awk '{print $1}' 2&gt; /dev/null</code></p>
<p><code>kubectl get hpa/${APP_NAME} --no-headers | awk '{print $1}' || true</code></p>
<p><code>kubectl get hpa/${APP_NAME} --no-headers | awk '{print $1}' &amp;&gt; /dev/null</code></p>
<p>All still print an error message.</p>
<p>So I have 2 questions:</p>
<ul>
<li>Is there a way to suppress this error message?</li>
<li>If I do find a way to suppress the message, will the variable I am setting the result of this command to still be populated in either case?</li>
</ul>
<p>Thanks</p>

stillmaticone17
<p>Assuming this error message comes from <code>kubectl</code>, you need to redirect stderr on its side of the pipe.</p>
<p><code>kubectl get hpa/${APP_NAME} --no-headers 2&gt;/dev/null | awk '{print $1}'</code></p>
<p>Each process in the pipeline has its own stdin, stdout, and stderr. The stdout of the first process is connected to the stdin of the second process, but stderr goes to the same place as it normally does unless you tell it to go somewhere else.</p>
