从gulp文件运行命令

问题描述 投票:0回答:1

我想基于从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();
})

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

javascript node.js gulp artillery
1个回答
0
投票

尝试用此替换您的'overridesPath'

 let overridesPath = ' --overrides ./services/' + argv.serviceName + '/overrides.slos.json';
© www.soinside.com 2019 - 2024. All rights reserved.