运行 来自 gulp 文件的命令

Running a command from gulp file

我想根据 gulp 命令传递的参数从 gulp 文件中 运行 火炮命令。

命令 运行:

gulp runner --serviceName employeeServices --scenario create-employee-details --env staging

这应该执行如下命令,该命令在 gulp 任务 (gulpfile.js)

中形成
artillery run -o report.json ./services/employeeServices/scenarios/create-employee-details.yml --config ./services/employeeServices/config.yml --overrides "$(cat ./services/employeeServices/overrides.slos.json)" -e staging

我遇到了以下错误。虽然 JSON 对 overrides.slos.json

有效
The values of --overrides does not seem to be valid JSON

gulpfile.js的代码:

const gulp = require('gulp');
const yargs = require('yargs');
const path = require('path');
const cp= require('child_process');

gulp.task('runner', async (done) => {
    let execute;
    if (argv.serviceName === undefined) {
        console.log('<------FAILED: Mandatory to specify Service name for performance testing------>');
    } else {
        let scenarioPath = './services/' + argv.serviceName + '/scenarios/' + argv.scenario + '.yml';
        let configPath = ' --config ./services/' + argv.serviceName + '/config.yml';
        let overridesPath = ' --overrides "$(cat ./services/' + argv.serviceName + '/overrides.slos.json)"';
        let env = ' -e ' + argv.env;
        execute = 'artillery run -o report.json ' + scenarioPath + configPath + overridesPath + env;
    }

    cp.execSync(execute,{shell:true}, (error, stdout, stderr) => {
        console.log(`stdout: ${stdout}`);
        console.log(`stderr: ${stderr}`);
        if (error !== null) {
            console.log(`exec error: ${error}`);
        }
    })

    await done();
})

期望的输出:它应该运行上面指定的命令

尝试用这个

替换你的'overridesPath'
 let overridesPath = ' --overrides ./services/' + argv.serviceName + '/overrides.slos.json';