Skip to content

cub trigger create

cub trigger create

Create a new trigger or bulk create triggers

Synopsis

Create a new trigger or bulk create multiple triggers by cloning existing ones.

SINGLE TRIGGER CREATION:

Create a new trigger: a function that runs automatically on units when an event happens.

A trigger runs on the units of every space that selects it, and on the units whose Target selects it. A space with neither WhereTrigger nor TriggerFilterID selects the triggers in it; one with either selects the triggers those match (cub space update --where-trigger or --trigger-filter), and a Target selects triggers the same way (cub target update). Within a selecting space, narrow which units a trigger runs on with --unit-filter or --where-unit-field. Instead of a single function, a trigger can run a stored invocation (--invocation).

A validating trigger whose function fails records a ValidationError on the unit, which blocks publishing a Release of it, promoting past a stage that requires Validated, and closing a ChangeSet whose workflow requires it, until the configuration or the trigger is fixed. With --warn, a failure records a ValidationWarning instead, which blocks nothing.

Events:

  • Mutation: Triggered when a resource is being modified
  • PostClone: Triggered after a resource is cloned

Toolchain Types:

  • Kubernetes/YAML: For Kubernetes YAML configurations
  • ConfigHub/YAML: For ConfigHub YAML configurations
  • AppConfig/Properties: For application Java Properties configurations
  • AppConfig/YAML: For application YAML configurations
  • AppConfig/TOML: For application TOML configurations
  • AppConfig/INI: For application INI configurations
  • AppConfig/Env: For application Env configurations
  • AppConfig/JSON: For application JSON configurations
  • AppConfig/Text: For application plain-text configurations

Example Functions:

  • vet-cel: Validate resources using CEL expressions
  • vet-placeholders: Ensure no placeholders exist
  • vet-schemas: Validate resources against their OpenAPI schemas
  • vet-no-merge-conflicts: Fail while a merge has changes still withheld on the unit
  • set-default-names: Set default names for cloned resources
  • set-annotation: Set annotations on resources

Function arguments can be provided as positional arguments or as named arguments using --argumentname=value syntax. Once a named argument is used, all subsequent arguments must be named. Use "--" to separate command flags from function arguments when using named function arguments.

BULK TRIGGER CREATION:

When no positional arguments are provided, bulk create mode is activated. This mode clones existing triggers based on filters and creates multiple new triggers with optional modifications.

Single Trigger Examples:

  # Create a trigger to validate replicas > 1 for Deployments
  cub trigger create --space my-space -o json replicated Mutation Kubernetes/YAML vet-cel 'r.kind != "Deployment" || r.spec.replicas > 1'

  # Create a trigger to enforce low resource usage (replicas < 10)
  cub trigger create --space my-space -o json lowcost Mutation Kubernetes/YAML vet-cel 'r.kind != "Deployment" || r.spec.replicas < 10'

  # Create a trigger to ensure no placeholders exist in resources
  cub trigger create --space my-space -o json complete Mutation Kubernetes/YAML vet-placeholders

  # Create a trigger to label every resource with its owning team
  cub trigger create --space my-space -o json label-team Mutation Kubernetes/YAML set-label team payments

  # Create a trigger to set default names for cloned resources
  cub trigger create --space my-space -o json rename PostClone Kubernetes/YAML set-default-names

  # Create a trigger to add a "cloned=true" annotation after cloning
  cub trigger create --space my-space -o json stamp PostClone Kubernetes/YAML set-annotation cloned true

  # Using named arguments for clarity (note the "--" separator)
  cub trigger create --space my-space -o json stamp PostClone Kubernetes/YAML -- set-annotation --annotation-key=cloned --annotation-value=true

Bulk Create Examples:

  # Clone all triggers matching a pattern with name prefixes
  cub trigger create --where "Slug LIKE 'app-%'" --name-prefix dev-,staging- --dest-space dev-space

  # Clone specific triggers to multiple spaces
  cub trigger create --trigger my-trigger --dest-space dev-space,staging-space

  # Clone triggers using a where expression for destination spaces
  cub trigger create --where "Slug LIKE 'app-%'" --where-space "Labels.Environment IN ('dev', 'staging')"

  # Clone triggers with modifications via JSON patch
  echo '{"Disabled": false}' | cub trigger create --where "Event = 'Mutation'" --name-prefix active- --from-stdin

  # Clone triggers matching specific criteria
  cub trigger create --where "ToolchainType = 'Kubernetes/YAML' AND FunctionName = 'vet-cel'" --name-prefix v2-
cub trigger create [<slug> <event> <config type> <function> [<arg1> ...]] [flags]

Options

      --allow-exists                  Allow creation of resources that already exist
      --annotation strings            annotations in key=value format; can separate by commas and/or use multiple instances of the flag
      --clearance stringArray         class of guarded reason this trigger's function is cleared for, as KEY, KEY=VALUE[;VALUE...], KEY!=VALUE[;VALUE...], or !KEY to refuse any path carrying KEY (repeatable). Part of the trigger's Hash, unlike --protect: changing it changes what a re-run lands
      --delete-gate strings           delete gates in key[=true] format; can separate by commas and/or use multiple instances of the flag
      --description string            description explaining the trigger's purpose and how to fix failures
      --dest-space strings            destination spaces for bulk create (can be repeated or comma-separated)
      --disable                       Disable trigger
      --display-name string           friendly name for the entity, which need not be unique or URL-safe; an entity without one is shown by its slug
      --dry-run                       report what the command would write, and write nothing
      --fail-open-after string        duration after which disconnected worker triggers fail open (e.g., 6h, 30m)
      --filename string               Read the ConfigHub entity's fields, as YAML or JSON, from file, URL (https://), or stdin (-), as --from-stdin does; mutually exclusive with --from-stdin
      --filter string                 Filter entity to apply to the list. Specify as 'space/filter' for cross-space filters or just 'filter' for current space. Supports both slugs and UUIDs. The filter will be combined with any --where clause using AND logic. Examples: "production-filters/security-check", "my-filter-uuid", "validation-rules"
      --filter-space string           filter entity containing WHERE expression to select destination spaces for bulk create (slug or UUID)
      --filter-unit string            filter, by slug or UUID, over Units selecting those to create from, with --from-backing-units
      --from-backing-units            create a Trigger from each ConfigHub/YAML Unit --where-unit, --filter-unit and --space select that describes one, in the Unit's space, with the Unit as its backing Unit
      --from-stdin                    Read the ConfigHub entity's fields, as YAML or JSON, from stdin; merged with command arguments on create, and merged with command arguments and existing entity on update. A field the entity does not have, or one only the server sets, is refused; cub <entity> explain lists the fields
      --guard stringArray             reason to record on the paths this trigger's function writes, as KEY=VALUE (repeatable). A later operation must be cleared for it before overwriting those paths, the trigger's next run included, so --clearance has to cover it. Part of the trigger's Hash, unlike --protect: changing it changes what a re-run leaves behind
  -h, --help                          help for create
      --hidden-reason string          hide the entity, giving the reason as a name such as Archived: lists and bulk operations leave it out unless --include-hidden names the reason (use '-' to clear, which shows the entity again)
      --include-hidden string[="*"]   Also select hidden entities, to list or to act on: those hidden for the given HiddenReasons, comma-separated, as in --include-hidden=BackingUnit, or for any reason when given no value or "*". ConfigHub/YAML Units, which hold the configuration of other entities, are hidden with the reason BackingUnit. A --where naming entities by Slug or ID selects them whether hidden or not
      --invocation string             invocation to execute (alternative to specifying function and arguments)
      --label strings                 labels in key=value format; can separate by commas and/or use multiple instances of the flag
      --name-pattern string           a pattern string for name generation of clones, prefix 'template:' to use a Go template with .SourceEntitySlug to access the original Trigger and .Labels to access variant labels, example: 'template:{{.SourceEntitySlug}}-{{.Labels.env}}'
      --name-prefix strings           name prefixes for bulk create (can be repeated or comma-separated)
      --other-data-source string      source of additional data to pass to the function (e.g., LastReleasedRevisionNum); defaults to the sources the function expects
  -o, --output string                 Output format. One of: json, yaml, name, wide, mutations, jq=<expr>, yq=<expr>, custom-columns=<spec>
      --patch-existing                with --from-backing-units, patch a Trigger a selected Unit already backs with what the Unit holds that it has not taken yet, rather than report that the Unit backs it
      --permission strings            permission in format Action:UserIDOrUsername, Action:group:GroupSlugOrID for a group you belong to, or Action:serviceaccount:ServiceAccountSlugOrID (e.g., Manage:user@example.com, View:group:platform, View:serviceaccount:deploy-bot, can be repeated)
      --protect                       record the paths this trigger's function writes as protected local overrides, so a later merge from upstream does not overwrite them; for a trigger that decides a value the unit then owns, such as a PostClone trigger customizing a variant
      --quiet                         No default output.
      --set stringArray               set a field of the Trigger by its path, as <path>=<value> (repeatable). A path is field names separated by dots; a list element is addressed as ?<key>=<value> or by position, as in Stages.?Name=prod.WhereSpace, and is added if it is not there. A list of plain values separates them with ';'; an object or a list of objects is given as YAML or JSON. A reference is given as it is elsewhere, by slug, <space>/<slug> or ID. With --patch, only a path with no list element in it
      --trigger strings               target specific triggers by slug or UUID for bulk create (can be repeated or comma-separated)
      --unit-filter string            filter entity (slug or UUID) to restrict which Units this trigger applies to
      --unset stringArray             clear a field of the Trigger by its path, or remove the list element the path ends at (repeatable)
      --variant-labels strings        labels for bulk create in the format of key1=value1|value2,key2=value1|value2|value3
      --verbose                       Detailed output, additive with default output
      --warn                          Set trigger to produce ValidationWarnings instead of ValidationErrors
      --where string                  Filter expression using SQL-inspired syntax. Supports conjunctions with AND. String operators: =, !=, <, >, <=, >=, LIKE, NOT LIKE, ILIKE, ~~, !~~, ~, ~*, !~, !~*. Pattern matching with LIKE/ILIKE uses % and _ wildcards. Regex operators (~, ~*, !~, !~*) support POSIX regular expressions. A related entity is referenced by prefix, as in "UpstreamUnit.Slug = 'base'"; when the reference names a list, a * segment matches any element, as in "FromLink.*.Slug = 'upgrade-app'". Examples: "Slug LIKE 'app-%'", "DisplayName ILIKE '%backend%'", "Slug ~ '^[a-z]+-[0-9]+$'"
      --where-resource string         metadata path expression to restrict which resources the trigger operates on
      --where-space string            where expression to select destination spaces for bulk create
      --where-unit string             where expression over Units selecting those to create from, with --from-backing-units
      --where-unit-field string       filter expression to restrict which Units this trigger applies to (its WhereUnit). It takes what --where does on unit list, attributes of what a unit refers to included, as in "Space.Labels.Environment = 'prod'"
      --with-backing-units            give each Trigger the bulk operation writes a backing Unit if it has none: a ConfigHub/YAML Unit holding its configuration, kept in step with it
      --worker string                 worker to execute the trigger function

Options inherited from parent commands

      --component string   the Component of --variant, when that names the variant alone; --variant <component>/<variant> says the same in one flag
      --context string     The context to use for this command
      --debug              Debug output
      --space string       space to operate in, by slug or UUID. Omitted, a list or bulk operation spans the organization and a single entity is named as <space>/<slug>; "*" means the same as omitting it
      --variant string     variant to operate in, as <component>/<variant>, or as <variant> with --component: the space naming that Component whose Variant label is <variant>. The same scope as --space, named by what it is rather than by the space's slug; the two cannot be combined

SEE ALSO