I have been trying for a few days on how to use an environment secret variable set in azure pipelines.
Here is source code where I get the environment variable value.
Here is the .env file I used with the value
Below is the TEST word successfully shown when I try to run in vscode via yarn start.
I setup environment variable and set variable as secret in the azure pipeline.
I followed some microsoft tutorial as well as some other answers here in stackoverflow.
I setup powershell task in azure pipelines to get secret variable.
All task run successfully. All task for IIS Deployment also run successfully.
But when I open the web app in the II Server, the result is TEST is not displayed at all.
Heading
If I use the pipeline variable as plaintext instead of secret, TEST is successfully displayed.
Did someone encountered this before and solved it?
Related
I am trying to deploy the Azure Web App in the Qa instance. I have created 3 different appsettings.json files with environment specific Client ID's in it
On the release pipeline for QA branch I am trying to use the test app service and set the settings like below
Release pipeline is all getting executed without any issues but when I try to access the application URL I get error like
Application ID is still pointing to the DEV one even though the appsettings.QA.json has different client ID of the Test App Registration where I set the reply URl and all correcctly.
I am not sure why my QA release pipeline is not using the ID's from the appsettings.QA.json. Can anyone please suggest me what is that I am missing here. Any help is greatly appreciated
Check how the application picks correct appsettings.json -file into use. As it picks Appsettings.Development.json in QA-environment, check how the environment is set in QA-environment App Service. Perhaps there is an environment-variable with the value "Development" in App Service configuration and that should be set to "QA"?
I have my connection string inside a .env file, which I don't commit into the git repo. And I have my app up and running on Azure.
So the way my app works is, when I push my code to Github, Azure Container Registry will build the image on the committed code, and then Azure App Service is going to pull and build a container for my app.
So my question is, how do I pass that connection string to the Docker container? What I could do is put the .env file into the git repo, but I don't think I should put it up there.
Thank you Rimaz Mohommed. Posting comment section discussion into Answer section to help other community users.
Couple of approaches
Add the Variables directly as part of the app settings and it should be available as part of your app environment.
Reference : https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-rm-web-app-deployment?view=azure-devops
You can pass/set your environment variables by Configure environment variables.
You can run this Azure CLI command as part of your devops pipeline (https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-cli?view=azure-devops)
I am deploying an Asp.Net Core application via Azure DevOps' Pipelines option and trying to set an environment variable on each of the target machines. Each deployment environment has its own settings file (for example "appsettings.Development.json") that the Asp.Net app chooses from when it starts up by reading the ASPNETCORE_ENVIRONMENT environment variable. I am using a Deploy Group to deploy the artifact to our on-site servers and that is working perfectly until it comes to setting the correct appsettings file to use.
I tried unsuccessfully to use a PowerShell task that has this inline script:
$Env:ASPNETCORE_ENVIRONMENT="$(EnvironmentName)"
All the pipeline tasks are executed successfully but the environment variable doesn't actually get applied on the target machine.
How can I set an environment variable on the target machines in a Deploy Group?
The above inline script of yours $Env:ASPNETCORE_ENVIRONMENT="$(EnvironmentName)" only set the variable in the current terminal window opened by the powershell task. The terminal window will be shut down after the powershell task is complete. We usually use below solutions to set environment variables in the pipeline.
If you want to set an environment variable on the target machines in the release pipeline. You can directly set a variable ASPNETCORE_ENVIRONMENT in the release pipeline Variables tab. See below:
Go to your release Edit page-->Variables tab-->Add new Variable-->Set the stage Scope
There is another way to set the environment variables dynamically using logging commands(Write-Host "##vso[task.setvariable..]) in the pipeline. See below inline script in powershell task:
echo "##vso[task.setvariable variable=ASPNETCORE_ENVIRONMENT]$(EnvironmentName)"
Please check the official document for more information.
Setting an environment variable that way isn't persistent, as you've observed. You'll need to the .NET environment variable methods to accomplish what you want.
[System.Environment]::SetEnvironmentVariable('ASPNETCORE_ENVIRONMENT', '$(EnvironmentName)' [System.EnvironmentVariableTarget]::Machine)
I have already created a service connection between existing subscription and ADO.
Problem statement 1:
I am running a simple ADO job which has just one Azure cli step. In the step I have checked the option to "Access service principal details in script". The inline script has just one statement
echo $servicePrincipalId
This works fine when I run in an ubuntu Agent but fails when I run using vs2017-win2016 server. Since we need to use windows agent could someone advice how to get this working?
Problem statement 2:
Once I get the service principal ie $servicePrincipalId I need to set this as an environmental variable so as to use this in my application (next step in pipeline) which reads of environmental variables.
Please could someone help?
Thanks.
Is it possible to set azure app service application settings (especially env variables) via deployment?
We are using local git repositories to deploy our NodeJS application to different azure appservices.
There are several environment variables required to run the application. I'd like to know if there is a way to insert those automatically while deploying the application so I do not have to set them manually for each application.
If its possible how does azure handles changes in the environment settings if I changed a variable afterwords? For example if I have sensitive data that I have to enter after deployment directly into the env variable?
Here's an example. Variables: Name=InitialValue
VAR_1=Test1234
VAR_2=Hello World
USERNAME=
PASSWORD=
USERNAME AND PASSWORD need to be empty an filled afterwords directly via azure portal. Now I redeploy. What happens to my USERNAME and PASSWORD entries? What happens if I change the value of VAR_1? In this case I'd like to have the environment variable changed.
In azure app service the environment variables can be set via Application Settings > App Settings.
It has a 'key-value' format where you can enter the variable name and its value.
Then in the code you can read them as "process.env.Username " and so on.