Gitlab CI: Using "environment" key with trigger in job
Asked Answered
C

4

6

I am looking to use the environment keyword as shown below in job which has trigger.


deploy:
 stage: deploy 
 environment:
   name: develop     
 variables:    
   ENV: develop    
 trigger:         
   include:
     - local: '<path to pipeline config>'

However, it is giving error "config contains unknown keys: environment"

It is working fine using "script" instead of trigger. Anyway it works with trigger ?

Cosec answered 19/1, 2022 at 10:22 Comment(1)
Found the same issue reported in gitlab the other day - gitlab.com/gitlab-org/gitlab/-/issues/350550. Hope it will be resolvedCosec
C
6

Yes apparently thats not allowed. I also felt this error and was expecting the environment config to be applicable on the child pipeline like below

sit-pipeline:
  trigger:
    include:
      - local: pipeline/sit-pipeline.yaml
  stage: deploy
  when: manual
  needs: ["sit-approval"]
  environment:
    name: sit
    url: http://sanjay-sit.com

But this gives an error This GitLab CI configuration is invalid: sit-pipeline config contains unknown keys: environment.

It would have been a good feature especially when we want to put some approval process and protect the environment.

Coveney answered 3/5, 2022 at 11:59 Comment(1)
this is not a solution to the issue. The answer from @tporeba is.Pouliot
E
5

Probably nothing you can do for child (same project) pipelines, but if somebody is looking for a solution for multi-project pipelines (like I was), then you can do the trigger via the API from script block.

This way of triggering is almost identical to using trigger keyword, AFAIK the only difference is that there is no strategy option, so you would have to implement necessary behavior yourself.

The good news is that GitLab notices the relation between upstream and downstream pipelines called via API and shows this in GUI. Another advantage is that you can retry such jobs, unlike trigger jobs. So this integrates nicely with Environments and Deployments feature.

See also the docs:

Egidio answered 9/12, 2022 at 12:56 Comment(0)
B
0

It looks like this feature has been implemented recently: https://gitlab.com/groups/gitlab-org/-/epics/8483 and it is possible to use environment in trigger jobs.

Braxton answered 27/9, 2024 at 1:35 Comment(0)
F
-1

You can't set environment on bridge jobs. You must set environment.name on the triggered job in the included config. E.g., in pipeline/sit-pipeline.yaml

Funkhouser answered 20/1, 2022 at 3:45 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.