diff --git a/astropy_helpers/commands/build_sphinx.py b/astropy_helpers/commands/build_sphinx.py
index <HASH>..<HASH> 100644
--- a/astropy_helpers/commands/build_sphinx.py
+++ b/astropy_helpers/commands/build_sphinx.py
@@ -177,14 +177,13 @@ class AstropyBuildSphinx(SphinxBuildDoc):
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT)
 
+            retcode = 1
             with proc.stdout:
                 for line in iter(proc.stdout.readline, b''):
                     line = line.strip(b'\n')
                     print(line.decode('utf-8'))
-                    if 'build succeeded.' in str(line):
+                    if 'build succeeded.' == str(line):
                         retcode = 0
-                    else:
-                        retcode = 1
 
             # Poll to set proc.retcode
             proc.wait()
build_sphinx now checks for "build succeeded." on any line.

This is to work around the effects of sphinx-gallery which prints
information about the gallery build out after the "build succeeded."
message.