@@ -223,8 +223,25 @@ async def update_image_build_status(self, buildrun_name: str, user_id: str) -> m
223223 return models .ShipwrightBuildStatusUpdate (update = None )
224224
225225 conditions = k8s_build_status .conditions
226+ # NOTE: You can get a condition like this in some cases during autoscaling or for other reasons
227+ # message: Not all Steps in the Task have finished executing
228+ # reason: Running
229+ # status: Unknown
230+ # /type: Succeeded
231+ # In this case we want to keep waiting - the buildrun is still running.
232+ # A fully successful completion condition looks like this:
233+ # reason: Succeeded
234+ # status: True
235+ # /type: Succeeded
236+ # See https://shipwright.io/docs/build/buildrun/#understanding-the-state-of-a-buildrun
237+ # NOTE: In the examples above I put / before the type field because mypy parses that and fails.
238+ # So I needed something to keep mypy happy. The real name of the field is "type"
226239 condition = next (filter (lambda c : c .type == "Succeeded" , conditions or []), None )
227240
241+ if condition is not None and condition .reason in ["Running" , "Pending" ]:
242+ # The buildrun is still running or pending
243+ return models .ShipwrightBuildStatusUpdate (update = None )
244+
228245 buildSpec = k8s_build_status .buildSpec
229246 output = buildSpec .output if buildSpec else None
230247 result_image = output .image if output else "unknown"
@@ -238,7 +255,7 @@ async def update_image_build_status(self, buildrun_name: str, user_id: str) -> m
238255 result_repository_git_commit_sha = git_obj_2 .commitSha if git_obj_2 else None
239256 result_repository_git_commit_sha = result_repository_git_commit_sha or "unknown"
240257
241- if condition is not None and condition .status == "True" :
258+ if condition is not None and condition .reason == "Succeeded" and condition . status == "True" :
242259 return models .ShipwrightBuildStatusUpdate (
243260 update = models .ShipwrightBuildStatusUpdateContent (
244261 status = models .BuildStatus .succeeded ,
0 commit comments