Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid .gitlab-ci.yml configuration with "environment: $env" usage #1441

Closed
vladadmin opened this issue Nov 28, 2024 · 3 comments · Fixed by #1443
Closed

Invalid .gitlab-ci.yml configuration with "environment: $env" usage #1441

vladadmin opened this issue Nov 28, 2024 · 3 comments · Fixed by #1443
Labels
bug Something isn't working

Comments

@vladadmin
Copy link

Minimal .gitlab-ci.yml illustrating the issue

---
.shared_rules:
  test_rule:
    - if: '$CI_COMMIT_BRANCH == "test"'
      variables:
        PIPELINE_ENVIRONMENT: test

test:
  image: alpine
  environment:
    name: $PIPELINE_ENVIRONMENT
  script:
    - echo "Test"
  rules:
    - !reference [.shared_rules, test_rule]

Expected behavior
https://gitlab.com/vladadmin/gitlab-ci-local-test/-/jobs/8493797441
https://gitlab.com/vladadmin/gitlab-ci-local-test/-/blob/test/.gitlab-ci.yml

Host information
Rocky Linux 9.5
gitlab-ci-local 4.56.0

Additional context
Get error text:

Invalid .gitlab-ci.yml configuration!
   • 'environment' property type must be string at test.environment
   • property 'name' must not have fewer than 1 characters at test.environment.name

and exit code <> 0

It may be possible to limit the warning to a variable in environment: $SOME_VAR, but the exit-code must be 0

@firecow firecow added the bug Something isn't working label Nov 29, 2024
@ANGkeith
Copy link
Collaborator

ANGkeith commented Nov 29, 2024

Not sure if we're referring to the same thing but this should be fixed

---
test:
  rules:
    - if: '"test" == "test"'
      variables:
        PIPELINE_ENVIRONMENT: test
  image: alpine
  environment:
    name: $PIPELINE_ENVIRONMENT    # expects this to be expanded to `test`
  script:
    - echo $PIPELINE_ENVIRONMENT

@vladadmin
Copy link
Author

Yes, it's the same thing - the same error occurs

@ANGkeith
Copy link
Collaborator

ANGkeith commented Nov 30, 2024

just take note that for the non-happy path,

---
test:
  rules:
    - if: '"test" != "test"'
      variables:
        PIPELINE_ENVIRONMENT: test
  image: alpine
  environment:
    name: $PIPELINE_ENVIRONMENT    # expects this to be expanded to `test`
  script:
    - echo $PIPELINE_ENVIRONMENT

this will fail the json-schema validation, and that is the expected behavior

and to get around this, i'll recommend to define a dummy value for the PIPELINE_ENVIRONMENT
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants