从gulp文件运行命令

时间:2019-10-10 11:54:19

标签: javascript node.js gulp artillery

我想根据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();
})

所需的输出:它应运行上面指定的命令

1 个答案:

答案 0 :(得分:0)

尝试以此替换“ overridesPath”

 let overridesPath = ' --overrides ./services/' + argv.serviceName + '/overrides.slos.json';