2

I'm working on ASP.NET project using Gitlab CI/CD and would like to inject the token that are on my CI/CD Settings>Variables, to my variable in the controller

controller.cs

            var clientId = THE_TOKEN_I_WANT_TO_INJECT1;
            var thumbprint = THE_TOKEN_I_WANT_TO_INJECT1;
            var tenantId = THE_TOKEN_I_WANT_TO_INJECT1;

Please advice, how to add Gitlab environment variable in my ASP.NET project

Taieb
  • 920
  • 3
  • 16
  • 37
  • Have you tried something like [`Environment.GetEnvironmentVariable`](https://learn.microsoft.com/en-us/dotnet/api/system.environment.getenvironmentvariable?view=net-6.0)? – sytech Apr 14 '22 at 21:18
  • Tried it, can't retrieve the variable unfortunately. I have a pipeline that get the variable from Gitlab. But couldn't find a way to get it inside ASP.NET – Taieb Apr 15 '22 at 13:56

1 Answers1

1

Steps to try:

  • Set an environment variable in GitLab.
  • Call printenv in your job scripts. Inspect the output to ensure the variable is set and available to your GitLab runner.
  • Add a line to your codebase to read and print the environment variable: https://stackoverflow.com/a/37387589/2675670
Richard
  • 2,226
  • 2
  • 19
  • 35