<p>I'm looking for a way to wait for Job to finish execution Successfully once deployed. </p>

<p>Job is being deployed from Azure DevOps though CD on K8S on AWS. It is running one time incremental database migrations using <a href="https://fluentmigrator.github.io" rel="nofollow noreferrer">Fluent migrations</a> each time it's deployed. I need to read <code>pod.status.phase</code> field. </p>

<p>If field is "<code>Succeeded</code>", then CD will continue. If it's "<code>Failed</code>", CD stops.</p>

<p>Anyone have an idea how to achieve this?</p>

<p>I think the best approach is to use the <strong><a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#wait" rel="nofollow noreferrer"><code>kubectl wait</code></a></strong> command:</p>

<blockquote>
  <p>Wait for a specific condition on one or many resources.</p>
  
  <p>The command takes multiple resources and waits until the specified
  condition is seen in the Status field of every given resource.</p>
</blockquote>

<p>It will only return when the Job is completed (or the timeout is reached):</p>

<p><code>kubectl wait --for=condition=complete job/myjob --timeout=60s</code></p>

<p>If you don't set a <code>--timeout</code>, the default wait is 30 seconds.</p>

<hr>

<p><strong>Note:</strong> <code>kubectl wait</code> was introduced on Kubernetes <a href="https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.11.md#sig-cli-1" rel="nofollow noreferrer">v1.11.0</a>. If you are using older versions, you can create some logic using <code>kubectl get</code> with <code>--field-selector</code>:</p>

<p><code>kubectl get pod --field-selector=status.phase=Succeeded</code></p>
