'cURL and shell task
I am using gulpfile.js in my project to download files and it is working fine.
var shell = require('gulp-shell');
gulp.task('folder_xyz', shell.task('curl --output xyz.zip --header "PRIVATE-TOKEN: theyuuin_io2_kj" "https://example.com/api/v4/download?job=xyz"'));
here everything is working fine and i am able to download the file. However i have set environment variable in GitLab called download_folder_xyz . Now i want to use this environment, want to replace Private token with new variable download_folder_xyz in the gulp.task() how can i do this ?
Solution 1:[1]
You can access any environment variable in nodejs via process.env object. Let's see an example. Assuming you want to access download_folder_xyz that is a environment variable
var shell = require('gulp-shell');
gulp.task('folder_xyz', shell.task(`curl --output xyz.zip --header "PRIVATE-TOKEN: ${process.env.download_folder_xyz}" "https://example.com/api/v4/download?job=xyz"`));
Solution 2:[2]
If download_folder_xyz has successfully been set as an environment variable, you can retrieve it from process.env. The env property of the process core module hosts all environment variables at the time the process has been started. See the docs for more information on this.
You can use the enviornment variable just as any other variable and interpolate in the task string. To replace the private token, this is the updated code:
const { download_folder_xyz } = process.env;
var shell = require('gulp-shell');
gulp.task('folder_xyz', shell.task(`curl --output xyz.zip --header "PRIVATE-TOKEN: ${download_folder_xyz}" "https://example.com/api/v4/download?job=xyz"`));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 |
