Skip to main content

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 in outcome.branch, the result in branch.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 in includePaths. 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.yaml still on the default branch.
  • An existing branch of that name is never overwritten: the change fails with 409 E7019 and 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.yaml or an included file differs from the default branch, none when nothing differs; an unreachable repository is 502 E7014.

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 E7020 the 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 vary properties: 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 in parameters.context (branch) and repeat the change.

Request​

Responses​

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.