0

I'm running the following command in the "execute shell" entry in my Jenkins job configuration.

AWS_ACCESS_KEY_ID=XXX AWS_SECRET_ACCESS_KEY=XXX CASS_HOSTNAME=XXX DB_HOSTNAME=XXX DB_PASSWORD=XXX DB_USERNAME=XXX EMAIL_REGION=XXX RED_HOSTNAME=XXXX RED_PORT=XXX npm run

How could I create a single variable for those parameters? I tried declaring a regular shell constant like:

readonly parameters="AWS_ACCESS_KEY_ID=XXX AWS_SECRET_ACCESS_KEY=XXX .."
$parameters npm run init_test_tenant

But I get the following error

/tmp/hudson6912171417213995775.sh: 4: /tmp/hudson6912171417213995775.sh: AWS_ACCESS_KEY_ID=XXX: not found

Bartzilla
  • 2,768
  • 4
  • 28
  • 37

2 Answers2

2

In order to avoid place eval in front of everything and open a hole in your code, you can use a trick:

export $parameters
npm run init_test_tenant

The difference from the attempt in your question: all variables will be visible to npm and all other commands you would execute after that, while VAR=value command syntax let VAR visible only to command.

Community
  • 1
  • 1
Joao Morais
  • 1,885
  • 13
  • 20
1

Prefix with env

readonly parameters="AWS_ACCESS_KEY_ID=XXX AWS_SECRET_ACCESS_KEY=XXX .."
env $parameters npm run init_test_tenant

Also if you do not need any other environment variables in your nodejs program you can add the -i option to env so that you get a clean environment for npm, but then you would have to address npm via full path ( eg: /usr/bin/npm ) and all other programs that might run within you nodejs program:

readonly parameters="AWS_ACCESS_KEY_ID=XXX AWS_SECRET_ACCESS_KEY=XXX .."
env -i $parameters /usr/bin/npm run init_test_tenant

Or add the PATH=/usr/bin/ to the $parameters constant like so:

readonly parameters="PATH=/usr/bin AWS_ACCESS_KEY_ID=XXX AWS_SECRET_ACCESS_KEY=XXX .."
env -i $parameters npm run init_test_tenant
Nicolae
  • 441
  • 6
  • 14