Howto return the deployment status of k8s/Openshift to your CI

  • Hi, we're currently implementing our deployment process to rollout new releases of our Java service onto Openshift. We intend to upgrade the service as soon as a new image gets pushed to the Docker Registry (or to update it manually via "oc rollout --latest")

    We currently have two related problems:

    • How to get the revision of our current deployment
    • How to get the status of that deployment

    Our only desparate approach to the second problem:
    oc rollout history dc/myapp
    187 Complete caused by an image change
    217 Failed caused by a config change

    Does anybody know how we could accomplish this?

  • APPUiO Staff

    If you are using Jenkins then the easiest way to implement this is by using the OpenShift Jenkins plugin which has explicit support for triggering builds on ImageStream changes, i.e. an image is pushed into the internal or an external registry:,

    Otherwise you can get the status of your deployment with something like this:

    shopt -s nocasematch
    # Get latest replication controller version
    LATEST_VERSION=`oc get dc/${DC} -o jsonpath='{.status.latestVersion}'`
    # Skip cancelled deployments
    while [[ `oc get rc/${DC}-${LATEST_VERSION} -o go-template=$'{{index .metadata.annotations ""}}\n'` == 'true' ]]; do
    # Get deployment status from latest replication controller
    oc get rc/${DC}-${LATEST_VERSION} -o go-template=$'{{index .metadata.annotations ""}}\n'

    This will return Complete for successful deployments.

    Note: We can't use JSONPath to retrieve the annotations because of K8S#31984. Should be fixed in OCP 3.5.

Log in to reply

Looks like your connection to APPUiO Discussion and Help Forum was lost, please wait while we try to reconnect.