I've created an Unit Test project which requires a key which is not public, so locally I can read it from the App.config but then Travis CI doesn't have this key.
So I've added an Environment Variable in Travis CI like this:
When the Travis CI build starts it displays my variable in the log:
Setting environment variables from repository settings
$ export TestKey=TestValue
But according to the log a simple test which reads the key fails with the error message Key not set as environment variable
:
[Test]
public void TestTravisEnvVariable()
{
string testKey= Environment.GetEnvironmentVariable("TestKey");
Assert.IsNotNullOrEmpty(testKey, "Key not set as environment variable");
}
The Environment.GetEnvironmentVariable
method reads the variable of the current process., but apparently the key can't be read in this case.
So how can I actually read this key?
Update: It is not clear to me why it didn't work in the first place but the sample above just works the second time I ran the build.