title: How to read Environment variable set by Travis CI in C#
body: <p>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.</p>
  
  <p>So I've added an Environment Variable in Travis CI like this:
  <img src="https://i.stack.imgur.com/zt9Ep.jpg" alt="Travis CI Environment Variables"></p>
  
  <p>When the Travis CI build starts it displays my variable in the log:</p>
  
  <blockquote>
    <p>Setting environment variables from repository settings<br>
    $ export TestKey=TestValue</p>
  </blockquote>
  
  <p>But according to the log a simple test which reads the key fails with the error message <code>Key not set as environment variable</code>:</p>
  
  <pre><code>[Test]
  public void TestTravisEnvVariable()
  {
      string testKey= Environment.GetEnvironmentVariable("TestKey");
  
      Assert.IsNotNullOrEmpty(testKey, "Key not set as environment variable");
  }
  </code></pre>
  
  <p>The <a href="https://msdn.microsoft.com/en-us/library/77zkk0b6(v=vs.110).aspx" rel="nofollow noreferrer"><code>Environment.GetEnvironmentVariable</code></a> method reads the variable of the current process.<strike>, but apparently the key can't be read in this case.</strike></p>
  
  <p><strike>So how can I actually read this key?</strike></p>
  
  <p><strong>Update:</strong>
  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.</p>