on 11-03-2022 5:25 PM
I'm trying to run the npm-script from the Jenkins pipeline via the SAP Project Piper's npmExecuteScripts:
npmExecuteScripts:
runScripts: ["testScript"]
That works! Now, I want to pass some arguments to my script.
According to the Project Piper documentation, there is a property scriptOptions, which cares about passing arguments to the called script:
Options are passed to all runScripts calls separated by a '--'. './piper npmExecuteScripts --runScripts ci-e2e --scriptOptions '--tag1' will correspond to 'npm run ci-e2e -- --tag1'
Unfortunately, I can't figure out what is the proper syntax for that command.
I've tried several combinations of using scriptOptions, e.g.:
scriptOptions: ["myArg"]
scriptOptions: ["myArg=myVal"]
and many others, but still no desired outcome!
How can I call an npm-script and pass arguments / parameters to the script using the Project Piper's npmExecuteScripts?
Did you try adding dashes?
scriptOptions: ['--myArg']
Regards,
Jamie
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey, jamie.cawley !
On the Jenkins side, I've tried:
npmExecuteScripts:
runScripts: ["testScript"]
scriptOptions: ["--montreal"]
And on the npm-script side, I've tried various options:
"testParams": "echo '*** My city: '$PIPER_scriptOptions' ***'",
"testParams": "echo '*** My city: '{$PIPER_scriptOptions}' ***'",
"testParams": "echo '*** My city: '${PIPER_scriptOptions}' ***'",
"testParams": "echo '*** My city: $PIPER_scriptOptions ***'",
"testParams": "echo '*** My city: {$PIPER_scriptOptions} ***'",
"testParams": "echo '*** My city: ${PIPER_scriptOptions} ***'",
"testParams": "echo '*** My city: '$npm_config_PIPER_scriptOptions' ***'",
"testParams": "echo '*** My city: '{$npm_config_PIPER_scriptOptions}' ***'",
"testParams": "echo '*** My city: '${npm_config_PIPER_scriptOptions}' ***'",
"testParams": "echo '*** My city: $npm_config_PIPER_scriptOptions ***'",
"testParams": "echo '*** My city: {$npm_config_PIPER_scriptOptions} ***'",
"testParams": "echo '*** My city: ${npm_config_PIPER_scriptOptions} ***'",
But none of them returns the desired result:
*** My city: montreal ***
What do you see in the log files when npm is running? Have you tried using $npm_config_montreal when it has a value?
Regards,
Jamie
jamie.cawley, I've tried $npm_config_montreal and the result:
*** My city: *** --montreal
The log file:
info npmExecuteScripts - run-script testParams
info npmExecuteScripts - running command: npm run testParams -- --montreal
info npmExecuteScripts -
info npmExecuteScripts - > myApp@1.0.0 testParams /var/apphome/.../.jenkins/workspace/myApp_master@2
info npmExecuteScripts - > echo '*** My city: '${npm_config_montreal}' ***' "--montreal"
info npmExecuteScripts -
info npmExecuteScripts - *** My city: *** --montreal
jamie.cawley, I've tried that already, unfortunately, no wanted outcome.
Jenkins Pipeline configuration:
npmExecuteScripts:
runScripts: ["testParams1", "testParams2", "testParams3", "testParams4", "testParams5", "testParams6"]
scriptOptions: ["--city=Montreal"]
package.json:
"scripts": {
"testParams1": "echo \"*** My city: '$city' ***\"",
"testParams2": "echo \"*** My city: '${city}' ***\"",
"testParams3": "echo \"*** My city: '$npm_config_city' ***\"",
"testParams4": "echo \"*** My city: '${npm_config_city}' ***\"",
"testParams5": "echo \"*** My city: '{$npm_config_city}' ***\"",
"testParams6": "echo \"*** My city: '{npm_config_city}' ***\""
}
Unfortunately, none of the scripts above provided the desired outcome: *** My city: 'Montreal' ***.
The used SAP Project Piper version: 1.147.0
Ok I think because there is a proceeding "--" they are not set to the config values. Can you just use them in the script you are trying to run?
scriptOptions: ["city=Montreal"]
in the script
const myArgs = process.argv.slice(2);
console.log(myArgs[0]);
Regards,
Jamie
User | Count |
---|---|
76 | |
9 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.