Drone

Access last step status

Is there a way accessing previous step execution status whether it is success or failure? Like using an env variable or something.

I have created simple bash image (not yet a plugin) to provide notification to Google Chat webhook. But currently I have no way to determine whether last step is success or failure, so as a workaround I use 2 steps just for notification

when:
  status
    - success

and

when:
  status
    - failure

IIRC there is an evironment variable telling you the current status. I couldn’t find it in the documentation, but just running the command env will list the variables.

e.g.

- name: test
  image: alpine
  commands:
  - env

Thanks for the hint. I already env and this is candidate that maybe solve my problem:

CI_BUILD_STATUS=success
CI_JOB_STATUS=success
DRONE_BUILD_STATUS=success
DRONE_JOB_STATUS=success
DRONE_STAGE_STATUS=success

However, those variables with prefix

CI_BUILD_*
CI_JOB_*
DRONE_BUILD_*
DRONE_JOB_*
DRONE_STAGE_*

seems to be redundant and all have same values aside from timestamp. Is there any documentation regarding these difference?

the DRONE_JOB_ and CI_ environment variables are legacy and are there for backward compatibility only, which is why they are not in the documentation. They are deprecated and should not be used. To learn more about supported environment variables see this section of the docs.

this is part of my drone.yml

- name: notif finish
    image: *cencored*
    pull: always
    environment:
      WEBHOOK:
        from_secret: CHAT_ROOM
      THREAD:
        from_secret: CHAT_THREAD
      BUILD_STARTED: ${DRONE_BUILD_CREATED}
      BUILD_URL: "${DRONE_BUILD_LINK}"
      BUILD_BRANCH: ${DRONE_COMMIT_BRANCH}
      BUILD_COMMIT: ${DRONE_COMMIT}
      BUILD_AUTHOR: ${DRONE_COMMIT_AUTHOR_NAME}
      BUILD_STATUS: ${DRONE_BUILD_STATUS}
      BUILD_STATUS_2: ${DRONE_STAGE_STATUS}
      BUILD_STATUS_3: ${DRONE_JOB_STATUS}
      BUILD_STATUS_4: ${CI_BUILD_STATUS}
      BUILD_STATUS_5: ${CI_JOB_STATUS}
      REPO_NAME: ${DRONE_REPO}
      REPO_COMMIT_URL: ${DRONE_COMMIT_LINK}
      REPO_URL: ${DRONE_REPO_LINK}
    commands:
      - echo DRONE_BUILD_STATUS:$DRONE_BUILD_STATUS
      - echo DRONE_STAGE_STATUS:$DRONE_STAGE_STATUS
      - echo DRONE_JOB_STATUS:$DRONE_JOB_STATUS
      - echo CI_BUILD_STATUS:$CI_BUILD_STATUS
      - echo CI_JOB_STATUS:$CI_JOB_STATUS
      - echo BUILD_STATUS:$BUILD_STATUS
      - echo BUILD_STATUS_2:$BUILD_STATUS_2
      - echo BUILD_STATUS_3:$BUILD_STATUS_3
      - echo BUILD_STATUS_4:$BUILD_STATUS_4
      - echo BUILD_STATUS_5:$BUILD_STATUS_5
      - echo BUILD_STATUS_6:$BUILD_STATUS_6
      - env

this is the result

+ echo DRONE_BUILD_STATUS:$DRONE_BUILD_STATUS
DRONE_BUILD_STATUS:failure
+ echo DRONE_STAGE_STATUS:$DRONE_STAGE_STATUS
DRONE_STAGE_STATUS:failure
+ echo DRONE_JOB_STATUS:$DRONE_JOB_STATUS
DRONE_JOB_STATUS:failure
+ echo CI_BUILD_STATUS:$CI_BUILD_STATUS
CI_BUILD_STATUS:failure
+ echo CI_JOB_STATUS:$CI_JOB_STATUS
CI_JOB_STATUS:failure
+ echo BUILD_STATUS:$BUILD_STATUS
BUILD_STATUS:
+ echo BUILD_STATUS_2:$BUILD_STATUS_2
BUILD_STATUS_2:
+ echo BUILD_STATUS_3:$BUILD_STATUS_3
BUILD_STATUS_3:
+ echo BUILD_STATUS_4:$BUILD_STATUS_4
BUILD_STATUS_4:
+ echo BUILD_STATUS_5:$BUILD_STATUS_5
BUILD_STATUS_5:
+ echo BUILD_STATUS_6:$BUILD_STATUS_6
BUILD_STATUS_6:
+ env
DRONE_SYSTEM_HOST=*cencored*
DRONE_BRANCH=master
DRONE_COMMIT_AUTHOR_AVATAR=*cencored*
DRONE_NETRC_MACHINE=*cencored*
DRONE_GIT_SSH_URL=*cencored*
DRONE_JOB_FINISHED=1567412329
CI=true
HOSTNAME=8067b7358d8a
DRONE_REPO_LINK=*cencored*
DRONE_STAGE_OS=linux
DRONE_COMMIT_AUTHOR=
DRONE_REPO_NAMESPACE=*cencored*
DRONE_TARGET_BRANCH=master
CI_BUILD_STARTED=1567412319
CI_WORKSPACE=*cencored*
DRONE_GIT_HTTP_URL=*cencored*
DRONE_RUNNER_HOSTNAME=bb25c162a863
SHLVL=1
DRONE_COMMIT_BRANCH=master
HOME=/root
BUILD_URL=*cencored*
DRONE_REPO_PRIVATE=true
DRONE_REPO_SCM=
DRONE_SYSTEM_PROTO=http
WEBHOOK=********
DRONE_STEP_NUMBER=4
DRONE_BUILD_STATUS=failure
REPO_URL=*cencored*
DRONE_REPO_VISIBILITY=private
CI_WORKSPACE_PATH=*cencored*
CI_JOB_STARTED=1567412319
DRONE_BUILD_ACTION=
DRONE_WORKSPACE_BASE=/go
DRONE_RUNNER_PLATFORM=linux/amd64
DRONE_COMMIT_BEFORE=
DRONE_STAGE_ARCH=amd64
DRONE_STAGE_STATUS=failure
DRONE_STAGE_NAME=test pipelione
DRONE_SOURCE_BRANCH=master
DRONE_REPO_BRANCH=master
DRONE_COMMIT_MESSAGE=preview for discourse
REPO_COMMIT_URL=*cencored*
DRONE_DEPLOY_TO=
CI_BUILD_FINISHED=1567412329
DRONE_SYSTEM_HOSTNAME=*cencored*
DRONE_JOB_STATUS=failure
REPO_NAME=*cencored*
DRONE_REMOTE_URL=*cencored*
DRONE_REPO_OWNER=*cencored*
DRONE_STAGE_KIND=pipeline
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DRONE=true
CI_NETRC_MACHINE=bitbucket.org
DRONE_BUILD_STARTED=1567412319
DRONE_BUILD_NUMBER=45
CI_JOB_FINISHED=1567412329
DRONE_WORKSPACE=*cencored*
DRONE_BUILD_LINK=*cencored*
DRONE_STAGE_VARIANT=
DRONE_STAGE_DEPENDS_ON=
DRONE_COMMIT_AFTER=4384814b60c570db1810d9caf8dacdc835a37371
DRONE_STAGE_NUMBER=1
DRONE_STAGE_STARTED=1567412319
BUILD_COMMIT=4384814b60c570db1810d9caf8dacdc835a37371
BUILD_STARTED=1567412304
DRONE_COMMIT=4384814b60c570db1810d9caf8dacdc835a37371
DRONE_RUNNER_HOST=bb25c162a863
DRONE_WORKSPACE_PATH=*cencored*
DRONE_JOB_STARTED=1567412319
DRONE_BUILD_EVENT=push
THREAD=********
DRONE_COMMIT_AUTHOR_EMAIL=*cencored*
DRONE_COMMIT_SHA=4384814b60c570db1810d9caf8dacdc835a37371
DRONE_BUILD_CREATED=1567412304
DRONE_REPO_NAME=*cencored*
DRONE_COMMIT_REF=refs/heads/master
CI_BUILD_STATUS=failure
DRONE_STAGE_MACHINE=bb25c162a863
DRONE_MACHINE=bb25c162a863
CI_WORKSPACE_BASE=/go
PWD=*cencored*
DRONE_BUILD_FINISHED=1567412329
DRONE_COMMIT_LINK=*cencored*
DRONE_REPO=*cencored*
DRONE_STEP_NAME=notif finish
BUILD_AUTHOR=*cencored*
DRONE_COMMIT_AUTHOR_NAME=*cencored*
DRONE_SYSTEM_VERSION=1.2.1
DRONE_STAGE_FINISHED=1567412329
CI_JOB_STATUS=failure
BUILD_BRANCH=master

Why I cannot assign only the build status, while other variable comes out fine?

${DRONE_BUILD_LINK} Will not work in .drone.yml.
Replace it with either $${DRONE_BUILD_LINK} or $DRONE_BUILD_LINK