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 tonpm 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
?
To solve the issue, it's important to bear in mind that in contrast to the regular argument-value mapping via the
npm_config_
-prefix, the SAP Project PiperscriptOptions
doesn't perform a mapping and passes an array of argument-value pairs «as is» instead, and then this array can be picked up viaprocess.argv
.The Jenkins pipeline configuration:
package.json:
The server-side script:
P.S. Just to compare, the regular way to pass an argument's value to the npm-script looks like:
and the server-side script:
The output:
The npm-script engine performs an argument-value mapping under the hood by using the
npm_config_
-prefix.