Gitlab course - Error when using a CI/CD variable inside .gitlab-ci.yml file

I am getting this error when trying to use a gitlabs ci/cd variable inside the .gitlab-ci.yml file.
workflow:
name: Solar System NodeJS Pipeline
rules:
- if: $CI_COMMIT_BRANCH == ‘main’ || $CI_COMMIT_BRANCH =~ /^feature/
when: always
- if: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^feature/ && $CI_PIPELINE_SOURCE == ‘merge_request_event’
when: always

stages: # List of stages for jobs, and their order of execution

  • test

variables:
MONGO_URI: ‘mongodb+srv://supercluster.d83jj.mongodb.net/superData’
MONGO_USERNAME: superuser
MONGO_PASSWORD: ‘$M_DB_PASSWORD’

unit-testing: # This job runs in the test stage.
stage: test
image: node:17-alpine3.14
before_script:
- npm install
script:
- npm test

Error:
$ npm test27> Solar [email protected] test28> mocha app-test.js --timeout 10000 --reporter mocha-junit-reporter --exit29Server successfully running on port - 300030error!! MongoError: password must be a string31Cleaning up project directory and file based variables00:0032ERROR: Job failed: exit code 8

I can’t be 100% sure I know what you tried, since when you paste your code into a forum post without using a code block (created with the </>) key, your code gets corrupted. But from the error, you probably have not set Gitlab’s environment variables correctly for the MongoDB instance’s password. Paste in your code again; it can be difficult in that course to find the correct password, since the instructor tends to bury them rather deep in his labs.

Rob, Thanks for responding. I was able to get past the error for the time being. But it seems like if you define a CI/CD variable for your project, then I don’t think you can directly assign it to another global, project variable in your code like below. MONGO_PASSWORD: ‘$M_DB_PASSWORD’. Either we need to use the CI/CD variable or extract it’s value and assign its value. Thanks.