diff --git a/cli/ssh.go b/cli/ssh.go index 5b89ca9fc56ad..aa8a4cad1f877 100644 --- a/cli/ssh.go +++ b/cli/ssh.go @@ -349,7 +349,7 @@ func getWorkspaceAndAgent(ctx context.Context, inv *clibase.Invocation, client * err error ) - workspace, err = namedWorkspace(inv.Context(), client, workspaceParts[0]) + workspace, err = namedWorkspace(ctx, client, workspaceParts[0]) if err != nil { return codersdk.Workspace{}, codersdk.WorkspaceAgent{}, err } @@ -362,6 +362,11 @@ func getWorkspaceAndAgent(ctx context.Context, inv *clibase.Invocation, client * if err != nil { return codersdk.Workspace{}, codersdk.WorkspaceAgent{}, err } + // Fetch up-to-date build information after completion. + workspace.LatestBuild, err = client.WorkspaceBuild(ctx, workspace.LatestBuild.ID) + if err != nil { + return codersdk.Workspace{}, codersdk.WorkspaceAgent{}, err + } } if workspace.LatestBuild.Transition == codersdk.WorkspaceTransitionDelete { return codersdk.Workspace{}, codersdk.WorkspaceAgent{}, xerrors.Errorf("workspace %q is being deleted", workspace.Name)