Skip to content

Environments and deployments

Configuring environments and deployment settings

Project deployment surfaces: environments, protected environments (project and group scope), deploy keys, pipeline schedules with their variables, and registry/package protection rules.

Example definition

gitlab_settings_projects:
  - path: platform/service
    environments:
      - name: production
        external_url: https://service.example.com
    protected_environments:
      - name: production
        deploy_access_levels:
          - access_level: 40
    deploy_keys:
      - title: deployer
        key: "ssh-ed25519 AAAA... deploy@example.com"
        can_push: false
    pipeline_schedules:
      - description: nightly build
        ref: main
        cron: "0 2 * * *"
        variables:
          ENVIRONMENT: production
    registry_protection_rules:      # pattern must start with the
                                    # project's full path
      - repository_path_pattern: "platform/service/prod*"
        minimum_access_level_for_push: maintainer
    package_protection_rules:
      - package_name_pattern: "@platform/*"
        package_type: npm
        minimum_access_level_for_push: maintainer

gitlab_settings_groups:
  - path: platform
    protected_environments:
      - name: production
        deploy_access_levels:
          - access_level: 40

Environments And Deployments Spec

environmentsarray of objects

Project environments matched by name. GitLab only deletes stopped environments; removing a running environment surfaces GitLab's error verbatim.

Properties of environments

namestringRequired

  Environment name and identity.


external_urlstring

  Environment URL; treated as a private value and reconciled by fingerprint.


tierstring

  Deployment tier.


descriptionstring

  Environment description.


cluster_agent_idinteger

  GitLab agent id associated with the environment.


kubernetes_namespacestring

  Kubernetes namespace associated with the environment.


flux_resource_pathstring

  Flux resource path associated with the environment.


auto_stop_settingstring

  GitLab auto-stop behavior.


slugstring

  Environment slug accepted by the GitLab API.


statestring

  Can be one of: present, absent. Default: present

Example:
environments:
  - name: production
    external_url: https://service.example.com
...

protected_environmentsarray of objects

Protected environments available on project and group entries, matched by name. Access arrays apply on create but are excluded from drift detection because they do not round-trip in request shape.

Properties of protected_environments

namestringRequired

  Environment name and identity.


deploy_access_levelsarray of objectsRequired on create

  Deployment access entries. Applied on create and excluded from drift detection.

Properties of each deploy_access_levels entry

  user_idintegerOne access target required

   ID of a user with access to the project. Declare one of user_id, group_id, or access_level.


  group_idintegerOne access target required

   ID of a group with access to the project. Declare one of user_id, group_id, or access_level.


  group_inheritance_typeinteger

   Membership behavior for a group_id: 0 for direct members or 1 for inherited members. Default: 0.


  access_levelintegerOne access target required

   Role allowed to deploy. Can be one of: 20, 30, 40, 60.


approval_rulesarray of objects

  Deployment approval rules. Applied on create and excluded from drift detection.

Properties of each approval_rules entry

  user_idintegerOne approval target required

   ID of a user allowed to approve. Declare one of user_id, group_id, or access_level.


  group_idintegerOne approval target required

   ID of a group allowed to approve. Declare one of user_id, group_id, or access_level.


  group_inheritance_typeinteger

   Membership behavior for a group_id: 0 for direct members or 1 for inherited members. Default: 0.


  access_levelintegerOne approval target required

   Role allowed to approve. Can be one of: 20, 30, 40, 60.


  required_approvalsinteger

   Number of approvals required from this rule. Default: 1.


statestring

  Can be one of: present, absent. Default: present

Example:
protected_environments:
  - name: production
    deploy_access_levels:
      - access_level: 40
...

deploy_keysarray of objects

Project deploy keys. This API surface does not mint keys; provide the public keys to configure.

Properties of deploy_keys

titlestringRequired on create

  Natural identity when unique and required to create a key.


idinteger

  Server-assigned lookup identity for an existing key when duplicate titles exist. Lookup-only.


keystringRequired on create

  Public key material. Readable but create-only; drift requires explicit recreation.


expires_atstring (date-time)

  Optional expiry. Readable but create-only; drift requires explicit recreation.


can_pushboolean

  Whether the key can push; reconciles in place.


statestring

  Can be one of: present, absent. Default: present

Example:
deploy_keys:
  - title: deployer
    key: "ssh-ed25519 AAAA..."
    can_push: false
...

pipeline_schedulesarray of objects

Project pipeline schedules. On a repository with no commits yet, GitLab rejects a short ref as ambiguous; use the fully qualified form such as refs/heads/main.

Properties of pipeline_schedules

descriptionstringRequired on create

  Natural identity when unique and required to create a schedule.


idinteger

  Server-assigned lookup identity for an existing schedule when duplicate descriptions exist. Lookup-only.


refstringRequired on create

  Branch or tag ref; reconciles with drift detection.


cronstringRequired on create

  Cron expression; reconciles with drift detection.


cron_timezonestring

  Cron timezone; reconciles with drift detection.


activeboolean

  Whether the schedule is active; reconciles with drift detection.


inputsarray of objects

  Values supplied to declared CI/CD inputs when the schedule runs.

Properties of each inputs entry

  namestringRequired

   Input name declared by the pipeline configuration.


  valuestring, array, number, or booleanRequired

   Value passed to that input.


variablesobject

  Schedule variables keyed by variable name. A scalar value is shorthand for a present variable with variable_type: env_var.

Properties of each structured variables value

  valuestringRequired when state is present

   Required when this variable entry's state is present (the default). Omit it when state: absent; deletion uses the variable's map key. This secret is never displayed or diffed.


  variable_typestring

   Can be one of: env_var, file. Default: env_var.


  force_secret_updateboolean

   Rewrite the secret value when no readable attribute drifted. Default: false.


  statestring

   Can be one of: present, absent. Default: present.


statestring

  Can be one of: present, absent. Default: present

Example:
pipeline_schedules:
  - description: nightly build
    ref: main
    cron: "0 2 * * *"
    variables:
      ENVIRONMENT: production
      OLD_VAR:
        state: absent
...

freeze_periodsarray of objects

Project deploy-freeze windows, matched by their cron-expression pair or an explicit server id.

Properties of freeze_periods

freeze_startstringRequired on create

  Start cron expression. Together with freeze_end, forms the natural identity and is required to create a window.


freeze_endstringRequired on create

  End cron expression. Together with freeze_start, forms the natural identity and is required to create a window.


idinteger

  Server-assigned lookup identity when duplicate windows exist. Lookup-only.


cron_timezonestring

  Cron timezone; reconciles with drift detection.


statestring

  Can be one of: present, absent. Default: present

Example:
freeze_periods:
  - freeze_start: "0 23 * * 5"
    freeze_end: "0 7 * * 1"
    cron_timezone: UTC
...

registry_protection_rulesarray of objects

Container repository protection rules. GitLab validates repository patterns server-side; a pattern must begin with the project's full path.

Properties of registry_protection_rules

repository_path_patternstringRequired

  Repository path pattern and identity.


minimum_access_level_for_pushstring or integer

  Minimum push access; reconciles via PATCH.


minimum_access_level_for_deletestring or integer

  Minimum delete access; reconciles via PATCH.


statestring

  Can be one of: present, absent. Default: present

Example:
registry_protection_rules:
  - repository_path_pattern: "platform/service/prod*"
    minimum_access_level_for_push: maintainer
...

package_protection_rulesarray of objects

Project package protection rules. GitLab validates patterns server-side; an npm pattern must be a valid package name, such as @group/prefix-*.

Properties of package_protection_rules

package_name_patternstringRequired

  Package name pattern and identity.


package_typestringRequired on create

  GitLab package type, such as npm.


minimum_access_level_for_pushstring or integer

  Minimum push access; reconciles via PATCH.


minimum_access_level_for_deletestring or integer

  Minimum delete access; reconciles via PATCH.


statestring

  Can be one of: present, absent. Default: present

Example:
package_protection_rules:
  - package_name_pattern: "@platform/*"
    package_type: npm
    minimum_access_level_for_push: maintainer
...

registry_tag_protection_rulesarray of objects

Container registry tag protection rules, distinct from repository rules that match image paths. Instance-gated: requires the next-generation container registry metadata API.

Properties of registry_tag_protection_rules

tag_name_patternstringRequired

  Tag pattern and identity.


minimum_access_level_for_pushstring or integerRequired on create

  Minimum push access; reconciles via PATCH.


minimum_access_level_for_deletestring or integerRequired on create

  Minimum delete access; reconciles via PATCH.


statestring

  Can be one of: present, absent. Default: present

A deployment without the metadata API refuses these rules with "GitLab container registry API not supported" because the instance does not expose the required API.

Example:
registry_tag_protection_rules:
  - tag_name_pattern: "v*"
    minimum_access_level_for_push: maintainer
    minimum_access_level_for_delete: maintainer
...