I am defining a variable JWT
, I will store in it a token which I will use later inside the code.
I'm going to obtain it at the before_script
step through a curl call.
The problem is that when I try to run the pipeline, it fails with the error:
Found errors in your .gitlab-ci.yml: Included file
.gitlab-ci.yml
does not have valid YAML syntax!
I have already read this Stack Overflow answer in order to properly interpolate USER
and PASS
environment variables.
This is my .gitlab-ci.yml
file:
build-dist:
environment:
name: develop
variables:
JWT: ""
stage: build
image: node:16-alpine
cache:
key:
files:
- yarn.lock
paths:
- node_modules
- .yarn
before_script:
- if [ -z "$USER" ] || [ -z "$PASS" ]; then exit 1; fi
- apk add curl
- JWT=$(curl -s -X POST -H "Content-Type: application/json" -d '{"username": "'"$USER"'","password": "'"$PASS"'"}' "https://example.com/token")
script:
- yarn install --pure-lockfile --cache-folder .yarn
- yarn build
How should I correct the follow line inside my .gitlab-ci.yml
in order to make it work?
- JWT=$(curl -s -X POST -H "Content-Type: application/json" -d '{"username": "'"$USER"'","password": "'"$PASS"'"}' "https://example.com/token")