Skip to main content

Preview a template change of an application component

POST 

/applications/:applicationId/components/:applicationComponentId/template/preview

Shows what changing the template of this resource to the given target would do, without changing anything (read-only: nothing is written, no branch is created and no build is started). Takes the same body as the matching PUT .../template change operation, including includePaths.


Intended flow:

  1. Call this operation with the target id, version, custom (and properties if needed).
  2. Show the user the effects with actor: PLATFORM (what CodeNOW will do itself), the effects with actor: USER (what the user must do) and the diff of the files with managedBy: REPOSITORY.
  3. If the user wants to see a scaffold file from otherFiles, read it on demand with POST .../template/preview/file (same body without includePaths, plus its path).
  4. Let the user choose which files go into the change branch: files[] with selectable: true and otherFiles that are not a symlink. .codenow.yaml is always included. Call this operation again with them in includePaths to see the resulting outcome and effects.
  5. Only after the user confirms, call PUT .../template with the same body. The resource switches to the new template immediately; the files go to a new branch the user merges into the default branch themselves.
    Submitting the resource's current template + version is not an error: the vsCurrentTemplate comparisons come back IDENTICAL; vsRepository still shows where the repository differs from the template.

Response:

  • repository: branch (the default branch) and commit the preview was computed against; there is no lock, the branch may move before the change. advancedMode: true when advanced mode is on (advancedMode.enabled in the branch's .codenow.yaml), false when it is off. null when the target template declares no advanced mode setting (e.g. docker-generic, helm-generic and other runnable templates; libraries, containers). Which files the user has to handle is decided per file by managedBy, not by this flag.

  • files[]: path is relative to the resource root. For a different template the list is the platform-owned set .codenow.yaml, Dockerfile, the helm/ directory. For the same template at a new version it also covers every other rendered file when the current version could be rendered, with managedBy: REPOSITORY and only vsCurrentTemplate (old version against new version).
    managedBy says who keeps a file up to date after the change; decide per file on it, never on advancedMode alone:
  • .codenow.yaml is always PLATFORM: the change merges it and always commits it to the change branch.
  • REPOSITORY: the user's own file. The repository's copy is authoritative; CodeNOW does not render it at build time. Its diff is a change the user has to make: include the path in includePaths or apply the diff by hand. This covers four cases:
    (1) the Dockerfile and the helm/ files when the resource's advanced mode is on (advancedMode.enabled in the default branch's .codenow.yaml; application components and agents only);
    (2) for a runnable target template (e.g. docker-generic, helm-generic), for every kind: the Dockerfile when the template needs a Dockerfile, the helm/ files when it needs helm files. This holds regardless of advanced mode: with advanced mode off they are still the user's files; do not ignore their diff;
    (3) a container's Dockerfile, always;
    (4) the other template files. They appear in files[] only when the target is the same template as the current one (a version change) and the current version could be rendered. For a different template they are listed only in otherFiles[], which has no managedBy.
  • PLATFORM (any other Dockerfile or helm/ file): rendered by CodeNOW from the template at every build and never part of the change branch; its diff is informational.
    selectable: true when the target template renders the path, the path is not .codenow.yaml, the file is managedBy: REPOSITORY, and 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. Such a path may be put into includePaths. Identical content does not make a file unselectable; an unchanged file is simply not part of the commit. A file that only the previous version renders is REPOSITORY but not selectable.

symlink: true when the path is a symbolic link in the repository or lies below a linked directory (e.g. helm is a link ⇒ helm/values.yaml). Such a path is never read (no comparison with the repository is returned for it), is not selectable, and naming it in includePaths answers 400 E7018.
Each file has up to two comparisons, omitted where they do not apply, each {result, current, target}: vsCurrentTemplate compares the current template's rendering with the target (omitted everywhere when the current version is no longer available — effect CURRENT_TEMPLATE_UNAVAILABLE); vsRepository compares the repository's file with the target (platform-owned files only). For .codenow.yaml the vsRepository target is the merged file the change will commit (omitted when the repository has no .codenow.yaml — effect CODENOW_YAML_ABSENT). result is CHANGED, IDENTICAL, TARGET_ONLY (only the target has the file) or OTHER_ONLY (only the current template or the repository has it). current and target are the base64-encoded file contents, null where the file does not exist.

  • otherFiles[]: every file the target template renders outside the platform-owned set (the application scaffold), names only, in both cases (so with the same template, when the current version could be rendered, they are also in files[]); inRepository: whether the path already exists; binary: the content cannot be represented as text; symlink: the path is a symbolic link in the repository or lies below a linked directory — it is never read and cannot be put into includePaths (400 E7018). CodeNOW does not require these files; each other one can be put into includePaths when it can be replaced in the repository (a repository file at a parent path or a directory at the path answers 400 E7018), or the user applies it by hand as far as the resource needs it. The content of one comes from POST .../template/preview/file; the content of a binary file is not returned; to get the file, include its path in includePaths so it is committed to the branch.
  • outcome: what confirming the change with this includePaths would do — branch (the name of the branch the change creates, starting with codenow/change-template-; null when nothing would be committed), branchExists (true: the change would fail with 409 E7019; the user merges or deletes the branch first), baseBranch and baseCommit it would start from, paths the commit would change (included files identical to the repository are skipped; empty: no branch would be created).
  • effects[]: {code, actor, message, key, value, previousValue, defaultValue}; the last four are optional strings, omitted when they do not apply. Key on code (the list may grow); message is end-user English.
    actor: PLATFORM — CodeNOW does it itself:
  • BRANCH_CREATED: the selected files are committed to the new branch;
  • CI_FILES_RENDERED_AT_NEXT_BUILD: the PLATFORM Dockerfile / helm/ files are rendered from the new template at the next build;
  • CODENOW_YAML_MERGED: .codenow.yaml is merged with the new template, not overwritten;
  • CODENOW_YAML_ABSENT: the repository has no .codenow.yaml;
  • PIPELINE_CHANGED: a pipeline that still equals the old template's default follows the new template's default. Carries key, previousValue → value (the target default);
  • PIPELINE_DEFAULT_KEPT: the pipeline equals the previous template's default and the new template has none, so it is kept. Carries key, value;
  • CI_PROPERTY_CHANGED: a CI setting that still equals the old template's default follows the new template's default. Carries key, previousValue → value, defaultValue (= value);
  • CI_PROPERTY_ADDED: a CI setting the current template does not declare is added with the target template's default. Carries key, value, defaultValue (= value);
  • CI_PROPERTY_DROPPED: a CI setting the new template no longer declares is removed. Carries key, previousValue; no value;
  • CI_PROPERTY_DEFAULT_KEPT: the CI setting's value equals the previous template's default and the new template has none, so it is kept. Carries key, value;
  • CURRENT_TEMPLATE_UNAVAILABLE: the current template version is no longer available; vsCurrentTemplate is omitted everywhere.
    actor: USER — the user has to do it:
  • MERGE_BRANCH: review the new branch and merge it into the default branch;
  • BRANCH_EXISTS: the branch already exists; merge or delete it before confirming;
  • TEMPLATE_SWITCHED_BEFORE_MERGE: the resource is on the new template at once, while the default branch keeps the old files until the merge;
  • APPLY_REPOSITORY_CHANGES: changed managedBy: REPOSITORY Dockerfile / helm/ files are not included; include them or apply the changes by hand. Not raised when only other files differ;
  • PIPELINE_KEPT: a customised pipeline is kept; the message names the new default. Carries key, value (the user's pipeline), defaultValue (what the new template would use; absent when it has none);
  • CI_PROPERTY_KEPT: a customised CI setting is kept; reported only when its default changed between the templates or the current template is unknown. Carries key, value (the user's value), defaultValue (what the new template would use; absent when it has none or it is blank);
  • CODENOW_YAML_NOT_MERGED: the repository's .codenow.yaml could not be parsed; CodeNOW leaves it as it is and the user adapts it by hand;
  • OTHER_TEMPLATE_FILES: the target template renders further files (otherFiles); they are committed only when included.
    Every pipeline effect (PIPELINE_…) and CI setting effect (CI_PROPERTY_…) carries key, the dotted .codenow.yaml path, plus the fields named in its line. Effects outside these two families carry none of the four fields.


Errors (problem+json, parameters.errorId): the same validation as the change — 400 E7011 / E7001 / E7018 or a property / not-ready rejection, 403, 404 — so a preview tells whether the change would be accepted; 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. 502 E7014 when the repository is unreachable or the resource's SCM provider / repository cannot be resolved (no partial preview; retry later, or check the resource's SCM settings if it persists), or when the resource's own path in the repository runs through a symbolic link (refused; retrying does not help); 502 without errorId when the preview is larger than the API passes on; 504 when CodeNOW did not answer in time (nothing changed; retry later). A running build or an existing branch does not block a preview: it never returns 409 (an existing branch shows as outcome.branchExists).

Request​

Responses​

What the change would do; nothing was changed