Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read environment variables in config/test suite #410

Closed
Tannenwedel opened this issue Oct 2, 2018 · 10 comments
Closed

Read environment variables in config/test suite #410

Tannenwedel opened this issue Oct 2, 2018 · 10 comments

Comments

@Tannenwedel
Copy link

Hi,

Is there a way to read environment/system variables in either the config or test suite? I'd like to run NBi unit tests on a CI server such as Bamboo and set certain values as environment variables.

Thanks!

@Seddryck Seddryck added this to the v1.19 milestone Oct 3, 2018
@Seddryck
Copy link
Owner

Seddryck commented Oct 3, 2018

It’s not supported as-is but you could achieve it with a script in a variable. Anyway, I’ll add this as a feature. Thx for the good idea.

@Tannenwedel
Copy link
Author

Thanks for the tip. Will it be possible to use those variables as part of a connection string? That way passwords wouldn't have to go in the file that holds the test suite.

@Seddryck
Copy link
Owner

Seddryck commented Oct 6, 2018

I plan to support two ways to use environment variables:

<variable name="myVar"/>
  <environment name="MyEnvVar"/>
</variable>

and for connection-strings it will be supported in the defaults and reference (not with inline definition).

<default apply-to="sut"/>
  <connectionString>
    <environment name="MyEnvConnStr"/>
  </connectionString>
</default>
<reference name="xyz"/>
  <connectionString>
    <environment name="MyOtherEnvConnStr"/>
  </connectionString>
</reference>

Note that for the connection-strings the evaluation of the value of the environment variable is executed during the read/load of the test-suite and not during the execution!

@Seddryck
Copy link
Owner

Seddryck commented Oct 8, 2018

Beta should be available at https://ci.appveyor.com/project/Seddryck/nbi/builds/19356719

@Tannenwedel
Copy link
Author

This works fine for me, thanks!

Seddryck pushed a commit that referenced this issue Nov 1, 2018
… and also to override the definition of a variable in a config file #410
@Seddryck Seddryck closed this as completed Nov 1, 2018
@Tannenwedel
Copy link
Author

Sorry for the late feedback,
Picking up environment variables when using the stand-alone NUnit tool works fine. However, when using the Nunit runner task within the Bamboo build server the bamboo-provided env vars are not being picked up and the connection strings are empty.

@Seddryck
Copy link
Owner

Seddryck commented Nov 15, 2018 via email

@fmms
Copy link

fmms commented Aug 6, 2023

@Seddryck could you give an explaination why NBi is looking at the user rather than process scope of a variable?

I think the code reason for my issue is: https://github.com/Seddryck/NBi/blob/90e0a283fbac3b69ce37551e3788bad25a2c8042/NBi.Core/Scalar/Resolver/EnvironmentScalarResolver.cs

I was expecting to just set an environment variable before executing nbi on my build agent. However, nbi does not read environment variables but only user defined environment settings.

@Seddryck
Copy link
Owner

Seddryck commented Aug 8, 2023

I probably didn't make the choice between user and process but between user and machine. But you're right that process souns to be a better choice. You can submit a PR if you want.

@fmms
Copy link

fmms commented Aug 9, 2023

I have opened ticket #717 and PR #718 for this however I have not been able to proof backward compatibility in the test suite… I suspect you might be able to see the mistake…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants