简体   繁体   中英

Gitlab CI CD variable are not getting injected while running gitlab pipeline

I am running the below code section in gitlab-ci.yml file:

  script:
- pip install --upgrade pip
- cd ./TestAutomation
- pip install -r ./requirements.txt

Below are the keys and values. So I have to pass any values to the pipeline with key as a variable ENV: dev

I have added all the above three variables in the GitLab CI CD variables sections by expanding them. just added a single value along with key

I also found like we can add variables in the.yml file itself as below. I am not sure how we can add multiple values for one key

variables:
 TEST:
   value: "some value" # this would be the default value
   description: "This variable makes cakes delicious"

When I run the pipeline I am getting errors as looks like these variables and values are not injected properly.

More details:

And the same error I am getting while running the pipeline. Hence my suspect is like Category variable is not injected properly when I am running through the pipeline

If needed I will show it on the share screen

please find attached an image snippet of my gitlab-ci.yml file- [![enter image description here][1]][1]

I am passing the below parameter while running pipeline - [![enter image description here][2]][2]

What I have observed is --the values associated with keys which I am passing as parameter or variables, those are not injected or replaced instead of key. So ideally ${Category} should be replaced with value smoke etc

When Gitlab CI CD variables are not getting injected into your pipelines as environment variables, please follow the following steps to verify.

  1. Check whether the variable is defined. You need to have at least the Maintainer role setup for your user. Go to Settings --> CI/CD --> Variables. You can see all project variables, and group variables (inherited).

  2. Next, check whether these variables are defined as Protected variables. If they are marked as Protected, then they are only exposed to protected branches or protected tags. I would suggest to uncheck this, if your current branch is not a protected branch . If not you can always make your current branch a protected one. 在此处输入图像描述

  3. Next, check whether your code is accessing the environment variables correctly. Based on your scripting language, just access as if you are accessing a regular environment variable.

  4. You don't really need to define these variables in the .gitlab-ci.yaml file. (Even though their documentation says so)

Hope this helps.

Variables set in the GitLab UI are not passed down to service containers. To set them, assign them to variables in the UI, then re-assign them in your.gitlab-ci.yml:

stages:
  - Test
# Added this to your yml file
variables:
  ENV: $ENV
  BROWSER: $BROWSER
  Category: $Category

ui_tests:
  stage: Test
  image: 
    name: joyzourky/python-chromedriver:3.8
    entrypoint: [""]
  tags:
  - micro
  only:
  - develop
  when: manual
  script:
    - pip install --upgrade pip 
    - cd ./src/Tests/UIAutomation
    - pip install -r ./requirements.txt
    - pytest -s -v --env=${ENV} --browser=${BROWSER} --alluredir=./reports ./tests -m ${Category}
  artifacts:
    when: always
    path:
    - ./src/Tests/UIAutomation/reports/
    - ./src/Tests/UIAutomation/logs/
    expire_in: 1 day

As @Keet Sugathadasa mentioned, the branch that triggers the CI must be protected; this was my case so I have to protect it by going to Settings > Repository > Protected branch and then protect the branch from there

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM