Drone

DRONE_BUILD_STATUS always success in Kubernetes

I recently switched from the legacy Kubernetes support in the main Drone app to the new drone-runner-kube and at that point I always started getting ‘success’ for DRONE_BUILD_STATUS despite a prior step (actually always the immediate prior step) failing.

I have this as my final step in a pipeline so that it can perform a few housekeeping actions responding to the status.

- name: deployment-update
  image: myrepo/drone-plugins/github-deployment:stable
  depends_on: [laststep]
  pull: always
  settings:
     ....
  when:
    status:
    - success
    - failure
    event:
    - push
    branch:
      include:
        - master

this is a known difference with the kubernetes runtime that requires a workaround. The pipeline containers are created at the same time, in the same pod. This impacts the status variables because pod environment variables are immutable, and cannot be updated to reflect the updated state of the pipeline. To workaround this, the runner writes the environment variables to a file [1] using the kubernetes downward API which you can then source to get the most up-to-date values [2].

[1] environment file path: /run/drone/env
[2] example reading environment file: https://github.com/drone-plugins/drone-slack/blob/master/main.go#L176:L178

Oh awesome! Makes sense. I’ll give that a shot next week. Thank you!