Skip to main content
Version: v5.6.1

opschain templates create

templates

opschain templates create <project> [-f <file.yaml>] [--code <code> --name <name> --git-remote <remote>] [--version <v> --git-rev <rev>]

Creates a template in the project. The code is the template's immutable identity (lowercase letters, numbers and underscores); --git-remote names one of the project's Git remotes, whose repository the template's versions pin revisions of.

With --version and --git-rev the first version is created in the same command, pinned to that branch, tag or commit. The two go together — a version without a revision (or the reverse) is refused. The version is a second write, but the pair behaves atomically: if the version fails (e.g. an unresolvable --git-rev), the just-created template is rolled back (DELETE on the template), so nothing is left behind — the error says the template was rolled back (nothing was created). Only if that rollback itself fails does the template survive, and the error names both failures.

Flags​

FlagMeaning
-f, --file <file.yaml>Strict YAML template definition. Keys: code, name, description, git_remote_name, template_type. An unknown key is refused by name. Flags win over file values.
--code <code>The template's immutable code.
--name <name>Display name (unique within the project).
--description <text>Description.
--git-remote <remote>Name of the project Git remote the template's versions pin revisions of.
--type <type>Template type: asset (the only type; defaulted).
--version <v>Also create this first version (requires --git-rev).
--git-rev <rev>The branch, tag or commit the first version pins (requires --version).

Exit codes​

CodeMeaning
0Created (template, and the first version when asked).
1The server refused the create, or the template was created but its first version was not.
2Usage error — mismatched version/revision pair, bad -f file, no server target.

Named errors​

  • --version and --git-rev go together — the first version needs both — exit 2.
  • template <project>/<code> was created, but its first version was not: <error> — the template exists; fix the revision and upsert the version (exit 1).
  • templates live on a server's projects — pass --server <url> or 'opschain context use <name>' — no server target (exit 2).

Examples​

Template only:

opschain templates create demo --code web_stack --name "Web stack" --git-remote origin
created template demo/web_stack (0199b8d0-…)

Template plus its first version in one command:

opschain templates create demo --code web_stack --name "Web stack" \
--git-remote origin --version 1.0.0 --git-rev v1.0.0
created template demo/web_stack (0199b8d0-…)
created version 1.0.0 (available, git rev v1.0.0 (3f2a91c))

See also​

  • opschain docs cli/templates-version-upsert — add further versions.
  • opschain docs cli/templates-assign — pin assets to a version.
  • opschain docs cli/git-remotes-create — create the remote first.
  • opschain learn 3.3 — the guided tour.