<p>I have a Kubernetes job that runs for some time, and I need to check if it failed or was successful. </p>

<p>I am checking this periodically: </p>

<pre><code>kubectl describe job/myjob | grep "1 Succeeded"
</code></pre>

<p>This works but I am concerned that a change in kubernetes can break this; say, the message is changed to "1 completed with success" (stupid text but you know what I mean) and now my grep will not find what it is looking for. </p>

<p>Any suggestions? this is being done in a bash script. </p>

<p>You can get this information from the job using jsonpath filtering to select the .status.succeeded field of the job you are interested in. It will only return the value you are interested in.</p>

<p>from <code>kubectl explain job.status.succeeded</code>:</p>

<blockquote>
  <p>The number of pods which reached phase Succeeded.</p>
</blockquote>

<p>This command will get you that field for the particular job specified:</p>

<pre><code>kubectl get job &lt;jobname&gt; -o jsonpath={.status.succeeded}
</code></pre>
