1

I am trying to run a build on TFS. One of the steps is setting an environment variable. This step, a Shell Script, fails on the following script:

export NODE_CONFIG_DIR= node_modules/test-automation-common/config

with a working directory of $(build.SourcesDirectory)/specmapper.

I am part of team that uses a shared private agent on a local Macbook Pro. I'm not sure of the exact OS it is running, but I know it's only a year or two old.

I'm trying to figure out how to set an environment variable on this machine. The machine is setup with a bash environment so the following should work:

  • export VARNAME=stringofthingyouwant

Due to a diligence of security, I cannot remote into the machine. I have been assured that export should be setup.

I am trying to run automated tests using Protractor and I need to setup a config directory variable that is not available until after npm install has been run, so I cannot use the export section in the 'runsvc.sh' as recommended here.


Edit: I was previously trying to use the command line step on a mac, which was now obviously not going to work. I mistook command line == terminal. I now have a Shell Script as noted above.

I am trying to run a build on TFS. One of the steps is setting an environment variable. This step (command line) fails with the message:

Failed which: Not found export: null
undefined failed with error: Failed which: Not found export: null
S.Huston
  • 254
  • 6
  • 18
  • Check this case to see whether it helps you: https://apple.stackexchange.com/questions/179371/shell-set-environment-variables-for-command. – Cece Dong - MSFT Feb 14 '18 at 06:11

2 Answers2

1

You should use ##vso[task.setvariable]value as explained in Logging Commands.

From a bash script, it is as simple as

echo ##vso[task.setvariable variable=myShinyNewVariable;]aSplendidValueForMyVar

Giulio Vian
  • 8,248
  • 2
  • 33
  • 41
  • 1
    I appreciate the comment. I ended up solving it by running the export and the process requiring the export in the same shell++ script step. I came to the solution from puzzling out that Environment variables are not saved step to step. – S.Huston Feb 15 '18 at 00:22
1

The solution was to use the "Shell++" step available as a build step. I determined that environment variables are cleaned up step-to-step, so instead of setting the variable in one step and running my "ng e2e" with an individual "Node" build step in which the previous environment variable wasn't available, I just put both into the "Shell++" as a script. Works fine now.

Documentation explicitly stating that environment variables are not saved across steps would have been nice to have.

@Giulio Vian's suggestion would probably work if you needed a variable across the whole job, but it did not work in my situation, as the path was not available until after "npm install" had been run.

S.Huston
  • 254
  • 6
  • 18