Given all the different languages involved, I don't think there is a way to use a common variable.
One way might be to have each block output some kind of string if it fails, and then in the last block you could search for the buffer for that string. Something like this:
* Section 1
#+BEGIN_SRC sh
false || echo "failed"-`date +'%s'`
#+END_SRC
#+RESULTS:
: failed-1621348872
#+BEGIN_SRC python
import time
if not False:
print(f'failed-{time.time()}')
#+END_SRC
#+RESULTS:
: failed-1621348926.125608
* Final section
#+BEGIN_SRC emacs-lisp
(format "There were %s failed blocks" (count-matches "failed-[0-9]" (point-min) (point-max)))
#+END_SRC
#+RESULTS:
: There were 2 failed blocks
Some alternatives include writing/appending to a file on error, and then counting the number of lines.
Another route is to use a :post header and search for the string there.
#+BEGIN_SRC emacs-lisp
(setq n-failures 0)
#+END_SRC
#+RESULTS:
: 0
#+name: fail-capture
#+BEGIN_SRC emacs-lisp :var data=""
(when (string-match "failed-[0-9]" data)
(incf n-failures)
(message "captured a failure in %s. n-failures=%s" data n-failures))
#+END_SRC
#+BEGIN_SRC sh :post fail-capture(*this*)
false || echo "failed"-`date +'%s'`
#+END_SRC
#+RESULTS:
: captured a failure in failed-1621349398. n-failures=1
#+BEGIN_SRC python :post fail-capture(*this*)
print('This did not fail')
#+END_SRC
#+RESULTS:
: nil
#+BEGIN_SRC python :post fail-capture(*this*)
print('This failed-9')
#+END_SRC
#+RESULTS:
: captured a failure in This failed-9
: . n-failures=2
All these approaches need you to handle and catch the errors. I think other kinds of errors would stop the export process. e.g. if a block errors out from division by zero or something.
I don't know how easy it would be to check if a src block succeeded or not. If it was easy, you might use the org-babel-after-execute-hook variable to update something when a failure is detected. Some blocks create an *Org-Babel Error Output buffer somewhere, but i don't know if this is 100% reliable across all blocks.
John
-----------------------------------
Professor John Kitchin (he/him/his)
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803