Skip to content

gitlab: a job without 'script' (trigger job) is demoted to an unparseable top-level block #24

Description

@jccguimaraes

A job is recognised only if its body has a script key:

if jobMap, ok := toStringAnyMap(doc[key]); ok {
    if _, hasScript := jobMap["script"]; hasScript {

A trigger job has no script — that is what makes it a trigger job. It falls through to the generic top-level branch, which warns and writes the map as a bare block named after the key:

build:
  script: [make]
deploy:
  trigger:
    include:
      - local: .gitlab/child.yml
    strategy: depend
  rules:
    - if: '$CI_COMMIT_BRANCH == "main"'
      when: manual

unparse:

warning: unsupported top-level key 'deploy' passed through
deploy {
  rules = [{ ... }]
  trigger {
    include  = [{ local = ".gitlab/child.yml" }]
    strategy = "depend"
  }
}

parse: Blocks of type "deploy" are not expected here.

The job is silently demoted and the file it produces does not parse. hclJobBlock already has a Trigger field, so the block shape is supported — only the detection is wrong.

Jobs with no script are ordinary GitLab: trigger jobs, and jobs that inherit script through extends. Detection should be "a top-level map that is not a reserved key and is not hidden (.-prefixed)" rather than "has a script". validatePipeline already enforces that a non-template job has a script somewhere in its chain, so the check does not need to live in the writer.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions