How to read GitLab variables in CI/CD inside package.json

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to read GitLab variables in CI/CD inside package.json



I have a private-module (private npm package) reference in my package.json file. Module is hosted on the company account (GitLab platform) and we use GitLab CI/CD.


private-module


package.json



Problem is that I need to insert access token of our repository on a place of <token> (you can see in the snippet).


access token


<token>



I need help with figuring out how to read gitlab environment variables inside my package.json.


"dependencies": {
"private-module": "git+http://<username>:<token>@url.git",
}



I found out that it is possible to create config key in package.json and define variables there but because of security reasons our variables need to be provided during CI step.


config


package.json




1 Answer
1



One possible solution is using envsubst:



Your package.json file:


"dependencies": {
"private-module": "git+http://<username>:${token}@url.git",
}



then running


envsubst '${token}' <package.json



${token} needs to exist as a Gitlab CI variable and the image you use needs the envsubst command. Otherwise you will need to replace the text with any other solution such as sed.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived