'How to get status of Kaniko build

After doing a Kaniko build to Openshift I notice that Jenkins displays the status as Success as long as nothing is wrong with the code itself in the Jenkinsfile.
However the after the Success message the build is still going on in Openshift and it could go wrong depending on the Dockerfile contexts etc.. How could I have Jenkins wait for the status of the build in Openshift and have it display its results in the Jenkins console?? Here is my code:

#!/usr/bin/env groovy
def projectProperties = [
  [$class: 'BuildDiscarderProperty',strategy: [$class: 'LogRotator', numToKeepStr: '5']]
]

    node {
withVault(configuration: [timeout: 60, vaultCredentialId: 'vault-approle-prd', vaultUrl: 'https://vault.example.redacted.com'], vaultSecrets: [[path: 'secrets/kaniko', secretValues: [[vaultKey: 'ghp_key']]]])
{
 sh 'echo $ghp_key > output.txt'
}
}

node  {
 GHP_KEY = readFile('output.txt').trim()
}

pipeline {
     agent {
    kubernetes {
      cloud 'openshift'
      idleMinutes 15
      activeDeadlineSeconds 1800
      yaml """
apiVersion: v1
kind: Pod
metadata:
  name: kaniko
spec:
  volumes:
  - name: build-context
    emptyDir: {}
  - name: kaniko-secret
    secret:
      secretName: regcred-${NAMESPACE}
      items:
        - key: .dockerconfigjson
          path: config.json
  securityContext:
    runAsUser: 0
  serviceAccount: kaniko
  initContainers:
    - name: kaniko-init
      image: ubuntu
  containers:
  - name: kaniko
    image: gcr.io/kaniko-project/executor:latest
    args: ["--context=git://${GHP_KEY}@github.com/Redacted/dockerfiles.git#refs/heads/${BRANCH}",
      "--destination=image-registry.openshift-image-registry.svc:5000/${NAMESPACE}/${IMAGE_NAME}:${IMAGE_TAG}",
      "--dockerfile=/jenkins-slave-ansible/Dockerfile",
      "--skip-tls-verify",
      "--verbosity=debug"]
    resources:
      limits:
        cpu: 1
        memory: 5Gi
      requests:
        cpu: 100m
        memory: 256Mi
    volumeMounts:
      - name: build-context
        mountPath: /kaniko/build-context
      - name: kaniko-secret
        mountPath: /kaniko/.docker
  restartPolicy: Never
"""
    }
  }
    parameters {
    choice(name: 'NAMESPACE', choices: ['cloud', 'ce-jenkins-testing'])
    string(defaultValue: 'feature/', description: 'Please enter your branch name', name: 'BRANCH')
    string(defaultValue: 'jenkins-slave-ansible', description: 'Please enter your image name (e.g.: jenkins-slave-ansible)', name: 'IMAGE_NAME')
    string(defaultValue: 'latest', description: 'Please add your tag (e.g.: 1.72.29)', name: 'IMAGE_TAG')
  }
   options {
      timestamps ()
  }
  stages {
    stage('Image Test') {
      steps {
         echo "Image name: ${IMAGE_NAME}"
         echo "Image tag: ${IMAGE_TAG}"
        }
      }
    }
  }



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source