fix(cli/ssh): Fetch up-to-date build info to avoid ws has no agents (#7650)

Fixes #5836
This commit is contained in:
Mathias Fredriksson
2023-05-24 12:37:22 +03:00
committed by GitHub
parent f47ecc29f0
commit b6c8e5be48

View File

@ -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)