Change the template of an agent
PUT/agent-swarms/:agentSwarmId/agents/:agentId/template
Changes the template of an existing resource and/or its version. Moving to a newer version of the same template is this
same operation with the same id and the newer version.
Call the matching POST .../template/preview operation first with the same body (including includePaths)
and confirm its effects and outcome with the user.
What it does:
- the resource switches to the target template immediately;
- CodeNOW creates a new branch from the default branch (its name starts with
codenow/change-template-; the preview shows it inoutcome.branch, the result inbranch.name) with one commit holding.codenow.yaml(merged, not overwritten: pipeline ids that still equal the old template's defaults and the CI property keys follow the new template, the user's other settings are kept) and the files listed inincludePaths. Included files identical to the repository are skipped; when nothing is left to commit, no branch is created. - The default branch is not touched. The user reviews the branch and merges it into the default branch themselves. Until then,
builds of the default branch use the new template with the
.codenow.yamlstill on the default branch. - An existing branch of that name is never overwritten: the change fails with 409
E7019and nothing changes.
includePaths: pick from the preview. Each entry is a preview files[].path with selectable: true, or an otherFiles[].path
for which it can be replaced in the repository: it is not a symbolic link and not below one, no repository file sits at a parent
path, and no repository directory sits at the path itself. otherFiles[].symlink shows the link case; a parent-file or directory conflict is not visible in advance.
Any other entry is rejected with 400 E7018. .codenow.yaml is always committed; naming it is ignored,
never an error.
Files not included stay with the user (see the preview's actor: USER effects).
Rules (enforced by CodeNOW):
- the target must be a template offered when creating a resource of the same kind;
- any existing version of the template is accepted, platform or custom (see
/templates/{templateId}/versions); - the resource must be ready (not creating or failed) and no build of it may be running;
- re-submitting the current template + version runs the same computation as the preview; the template reference does not change.
A branch is created when
.codenow.yamlor an included file differs from the default branch, none when nothing differs; an unreachable repository is 502E7014.
Moving many resources to the newest platform version: list the resources, keep those with template.outdated == true
(the template object is on list responses, no detail calls needed), preview each and call this operation for each with
{"id": template.id, "custom": template.custom, "version": template.latestVersion}.
Returns {template, branch}: template is the resource's template after the change; branch is
{name, baseBranch, baseCommit, commit, paths, webUrl} of the new branch (paths: what the commit changes;
webUrl: currently always null), or null when nothing was committed.
Report branch.name to the user: the file changes take effect only after the user merges that branch into
baseBranch; the template switch is immediate, and deleting the branch does not undo it.
Lost answer: if this call times out (504) or the connection drops, the change may still have completed — the template is switched
and the branch exists. Before repeating the call, read the resource (its template) and look for the branch. A repeated
call then answers 409 E7019; in that situation E7019 does not mean that nothing changed.
Errors (problem+json, parameters.errorId where CodeNOW assigns a code):
- 400
E7011/E7001/E7018, or a property / not-ready rejection: the change is not allowed; nothing changed; - 400
E7020the target template itself cannot be rendered (context:templateId,version,path; the message names the template, the file and the line). Nothing was changed. Do not retry and do not varyproperties: tell the user.
- 404: the resource does not exist (or not under this parent);
- 409
E7013: a build of the resource is running; nothing changed; retry after it finishes; - 409
E7019: the branch already exists; this call changed nothing; the user merges or deletes it, then repeats the change (after a lost answer, see above: the earlier call may have created that branch and switched the template); - 502 / 504 without
errorId: CodeNOW's answer was lost or did not come in time; the change may have completed (see above); - 502
E7014: the repository is unavailable (unreachable, or the resource's SCM provider / repository cannot be resolved); nothing changed; retry later, or check the resource's SCM settings if it persists. Also when the resource's own path in the repository runs through a symbolic link: such a resource is refused, and retrying does not help; - 502
E7015: the branch could not be created; nothing changed; retry later; - 500
E7016: the branch was created, but the template could not be changed and the branch could not be removed again. Do not retry automatically. Tell the user to delete the branch named inparameters.context(branch) and repeat the change.
Request
Responses
- 200
- 400
- 401
- 403
- 404
- 409
- 429
- 500
- 502
- 504
Template was changed: template is the resource's template after the change, branch the new branch
holding the file changes (null when there was nothing to commit). Tell the user the branch name: the file changes take
effect only once they merge it, while the template switch is already in effect and deleting the branch does not undo it.
The change (or its preview) was rejected. Coded rejections carry parameters.errorId and parameters.context (key/value pairs) in the problem+json body:
E7011the template is not valid for this resource type (context:templateId,customTemplate,resourceType);E7001the version does not exist (context:id,version).E7020the target template itself cannot be rendered (context:templateId,version,path; the message names the template, the file and the line). Nothing was changed. Do not retry and do not varyproperties: tell the user.
E7018anincludePathsentry is not offered: not afiles[]path withselectable: true, nor anotherFilespath that can be replaced in the repository (a symbolic link or below one, a repository file at a parent path, a repository directory at the path). Run the preview again and pick again (context:path)..codenow.yamlinincludePathsis ignored, never this error.
Without anerrorId: a template property failed validation (same as on creation), or the resource is not ready.
No valid API key provided.
The caller may not edit the resource.
The resource does not exist (or not under this parent). Nothing was changed.
Nothing was changed. parameters.errorId:
E7013a build of the resource is running (parameters.context:appComponentId,buildId). Retry after the build finishes or cancel it;E7019the change branch already exists (context:appComponentId,branch); it is never overwritten. Merge or delete the branch, then repeat the change. If this answers a repeated call after a lost answer (timeout, dropped connection), the earlier call may have completed: read the resource'stemplateand look at the branch before doing anything else.
Too many requests hit the API too quickly. We recommend an exponential backoff of your requests.
E7016 the change is incomplete: the change branch was created, but the template could not be changed and the branch could not
be removed again (context: appComponentId, branch). Do not retry automatically: a retry fails with E7019
while the branch exists. Tell the user to delete the branch, then repeat the change.
Any other 500 without this code: something went wrong on CodeNOW's end.
With parameters.errorId nothing was changed; retry later:
E7014the repository's default branch could not be read, or the resource's SCM provider / repository cannot be resolved, or the resource's own path in the repository runs through a symbolic link (refused; retrying does not help) (context:appComponentId);E7015the change branch could not be created (context:appComponentId,branch).
WithouterrorId: the connection to CodeNOW dropped before it confirmed the change. The change may still have completed: read the resource'stemplateand look for the branch before repeating it.
CodeNOW did not confirm the change in time. The change may still have completed (template switched, branch created): read the
resource's template and look for the branch before repeating it; a repeated call then answers 409 E7019.