if(DASHBOARD_FAILURE OR DASHBOARD_UNSTABLE)
  notice("CTest Status: NOT PUSHING DOCKER IMAGE BECAUSE BAZEL BUILD WAS NOT SUCCESSFUL")
else()
  notice("CTest Status: PUSHING DOCKER IMAGE")

  if(NOT DASHBOARD_UNSTABLE)
    set(DOCKER_LOGIN_ARGS "login --username $ENV{DOCKER_USERNAME} --password-stdin")
    separate_arguments(DOCKER_LOGIN_ARGS_LIST UNIX_COMMAND "${DOCKER_LOGIN_ARGS}")
    execute_process(COMMAND "sudo" "${DASHBOARD_DOCKER_COMMAND}" ${DOCKER_LOGIN_ARGS_LIST}
      RESULT_VARIABLE DOCKER_LOGIN_RESULT_VARIABLE
      INPUT_FILE "$ENV{DOCKER_PASSWORD_FILE}"
      COMMAND_ECHO STDERR)
    if(NOT DOCKER_LOGIN_RESULT_VARIABLE EQUAL 0)
      append_step_status("BAZEL PUSHING DOCKER IMAGE (DOCKER LOGIN)" UNSTABLE)
    endif()
  endif()

  if(NOT DASHBOARD_UNSTABLE)
    set(DOCKER_PUSH_IMAGE_DISTRIBUTION_DATE_ARGS "push robotlocomotion/drake:${DASHBOARD_UNIX_DISTRIBUTION_CODE_NAME}-${DATE}")
    separate_arguments(DOCKER_PUSH_IMAGE_DISTRIBUTION_DATE_ARGS_LIST UNIX_COMMAND "${DOCKER_PUSH_IMAGE_DISTRIBUTION_DATE_ARGS}")
    foreach(RETRIES RANGE 3)
      execute_process(COMMAND "sudo" "${DASHBOARD_DOCKER_COMMAND}" ${DOCKER_PUSH_IMAGE_DISTRIBUTION_DATE_ARGS_LIST}
        RESULT_VARIABLE DOCKER_PUSH_IMAGE_DISTRIBUTION_DATE_RESULT_VARIABLE
        COMMAND_ECHO STDERR)
      if(DOCKER_PUSH_IMAGE_DISTRIBUTION_DATE_RESULT_VARIABLE EQUAL 0)
        break()
      endif()
      sleep(15)
    endforeach()
    if(NOT DOCKER_PUSH_IMAGE_DISTRIBUTION_DATE_RESULT_VARIABLE EQUAL 0)
      append_step_status("BAZEL PUSHING DOCKER IMAGE (ROBOTLOCOMOTION/DRAKE:${DASHBOARD_UNIX_DISTRIBUTION_CODE_NAME}-${DATE})" UNSTABLE)
    endif()
  endif()

  if(NOT DASHBOARD_UNSTABLE)
    set(DOCKER_PUSH_IMAGE_DISTRIBUTION_ARGS "push robotlocomotion/drake:${DASHBOARD_UNIX_DISTRIBUTION_CODE_NAME}")
    separate_arguments(DOCKER_PUSH_IMAGE_DISTRIBUTION_ARGS_LIST UNIX_COMMAND "${DOCKER_PUSH_IMAGE_DISTRIBUTION_ARGS}")
    foreach(RETRIES RANGE 3)
      execute_process(COMMAND "sudo" "${DASHBOARD_DOCKER_COMMAND}" ${DOCKER_PUSH_IMAGE_DISTRIBUTION_ARGS_LIST}
        RESULT_VARIABLE DOCKER_PUSH_IMAGE_DISTRIBUTION_RESULT_VARIABLE
        COMMAND_ECHO STDERR)
      if(DOCKER_PUSH_IMAGE_DISTRIBUTION_RESULT_VARIABLE EQUAL 0)
        break()
      endif()
      sleep(15)
    endforeach()
    if(NOT DOCKER_PUSH_IMAGE_DISTRIBUTION_RESULT_VARIABLE EQUAL 0)
      append_step_status("BAZEL PUSHING DOCKER IMAGE (ROBOTLOCOMOTION/DRAKE:${DASHBOARD_UNIX_DISTRIBUTION_CODE_NAME})" UNSTABLE)
    endif()
  endif()

  if(DASHBOARD_UNIX_DISTRIBUTION_CODE_NAME STREQUAL "bionic")
    if(NOT DASHBOARD_UNSTABLE)
      set(DOCKER_PUSH_IMAGE_DATE_ARGS "push robotlocomotion/drake:${DATE}")
      separate_arguments(DOCKER_PUSH_IMAGE_DATE_ARGS_LIST UNIX_COMMAND "${DOCKER_PUSH_IMAGE_DATE_ARGS}")
      foreach(RETRIES RANGE 3)
        execute_process(COMMAND "sudo" "${DASHBOARD_DOCKER_COMMAND}" ${DOCKER_PUSH_IMAGE_DATE_ARGS_LIST}
          RESULT_VARIABLE DOCKER_PUSH_IMAGE_DATE_RESULT_VARIABLE
          COMMAND_ECHO STDERR)
        if(DOCKER_PUSH_IMAGE_DATE_RESULT_VARIABLE EQUAL 0)
          break()
        endif()
        sleep(15)
      endforeach()
      if(NOT DOCKER_PUSH_IMAGE_DATE_RESULT_VARIABLE EQUAL 0)
        append_step_status("BAZEL PUSHING DOCKER IMAGE (ROBOTLOCOMOTION/DRAKE:${DATE})" UNSTABLE)
      endif()
    endif()

    if(NOT DASHBOARD_UNSTABLE)
      set(DOCKER_PUSH_IMAGE_LATEST_ARGS "push robotlocomotion/drake:latest")
      separate_arguments(DOCKER_PUSH_IMAGE_LATEST_ARGS_LIST UNIX_COMMAND "${DOCKER_PUSH_IMAGE_LATEST_ARGS}")
      foreach(RETRIES RANGE 3)
        execute_process(COMMAND "sudo" "${DASHBOARD_DOCKER_COMMAND}" ${DOCKER_PUSH_IMAGE_LATEST_ARGS_LIST}
          RESULT_VARIABLE DOCKER_PUSH_IMAGE_LATEST_RESULT_VARIABLE
          COMMAND_ECHO STDERR)
        if(DOCKER_PUSH_IMAGE_LATEST_RESULT_VARIABLE EQUAL 0)
          break()
        endif()
        sleep(15)
      endforeach()
      if(NOT DOCKER_PUSH_IMAGE_LATEST_RESULT_VARIABLE EQUAL 0)
        append_step_status("BAZEL PUSHING DOCKER IMAGE (ROBOTLOCOMOTION/DRAKE:LATEST)" UNSTABLE)
      endif()
    endif()
  endif()
endif()
