I'm in the process of setting up TeamCity on Azure, more specifically I'm setting up some build agents. Certain properties of the build agents are configured via the buildAgent.properties file like name, port etc. I would like to call the agent the name of the computer it is located on but I can't find (and indeed don't know if this is possible) anyway to use environment variables to set the agent name i.e env.COMPUTERNAME?
The only way i seem to be able to do this is by hard coding the name
#Generated properties (see buildAgent.dist.properties for description)
name=tc-agent-001 #is it possible to use environment variable here?
ownPort=9090
serverUrl=http\://mybuildserver.mycompany.com
workDir=C\:\\BuildAgent\\work
tempDir=C\:\\BuildAgent\\temp
#User defined properties
env.TEAMCITY_JRE=C\:\\BuildAgent\\jre
Has anyone figured out a way to do this?
Our agents had this behaviour by default. It is the name property that appears in the env.COMPUTERNAME environment variable, and this was the hostname of each VM.
If your machine hostname is different to the listed name, just change that parameter, but as this file is just a parsed list of settings, there's not a way to have it programatically detect the hostname for you. - unless you write a script to detect the hostname of a machine and then modify the properties file.
Related
i'm trying to setup my project in azure. For this i created an app service and under settings/configuration i added some "Application Settings", which in my understanding are environment variables. However i deployed my docker image which azure pipelines and everything is okay, but when i connect through ssh to the instance and call 'env' i don't see any of my environment variables.
From the documentation i should be able to call them inside php as every other env variable (getenv..). Maybe i miss something or my understanding of this app settings are incorrect.
Would be great if somebody has an idea about what is wrong, if you need more informations hit me up.
Partly, you did not make mistake on the way of accessing setting/configuration which set as environment variable. The getenv() is correct.
when i connect through ssh to the instance and call 'env' i don't see
any of my environment variables
I think this issue may caused by your script. When you access these setting keys, do not lost Prefixed. This is the important way to access and get these environment variable. For example, if you want to access app settings, the name of the corresponding environment variable should prepended with APPSETTING_.
At this time, the sample script for PHP script should be:
<?php
$appsetting = getenv('APPSETTING_{Key}'); echo $appsetting;
?>
Note: The {key} is the key name you configured in Azure app service.
For the configuration which under Connection Strings, it should be added with other prefixed. As you know, when you create these connection strings, you need to choose Type:
For these setting, the connection strings are available as environment
variables, prefixed with the following connection types:
SQL Server: SQLCONNSTR_
MySQL: MYSQLCONNSTR_
SQL Database: SQLAZURECONNSTR_
Custom: CUSTOMCONNSTR_
For more details, check this doc: https://learn.microsoft.com/en-us/azure/app-service/configure-common#configure-connection-strings
Setting Environment Variables
In Azure Portal, locate your app service
On the left pane, click Configuration
Under Application settings, click "New application setting"
Fill in the name and value for the environment variable
Click "OK", then at the top, click "Save"
Accessing Environment Variables
With PHP
Replace ENV_VAR_NAME with your own environment variable name.
$var = getenv('ENV_VAR_NAME');
With CLI - Linux
You can use your preferred SSH client, but in this case I'll use the one in Azure Portal.
In Azure Portal, locate your app service
On the left pane, click "SSH"
Click "Go"
Type printenv ENV_VAR_NAME, replace ENV_VAR_NAME with your environment variable.
I found this article which explains a little bit more how the whole stuff works.
https://omgdebugging.com/2018/10/05/how-to-export-environment-variables-in-azure-web-app-for-containers/
However i sticked to this article and used the provided workaround. If somebody knows a better solution, please let me know
I have published my linux container to App Services for Containers.
The way my container works is that it reads settings like API keys and connections strings from environment variables inside the running container.
I found a stack overflow post that says to set the env vars I need to use the "App Settings" in Azure. The problem is all the env vars have a colon in them, like:
database:connectionString=myConnectionString
App Services will not allow me to set a key that has a colon in it, however this is a perfectly valid syntax for a linux environment variable.
I really don't want to inject passwords during the build process into the actual image as that could cause a lot of issues.
How can I set an env var in App Services for containers that has a : in the key?
You could set your connection string, however : should be replaced by __(i.e. double underscore).You could find this from this doc. This principle is for Linux App.
Hope this could help you, if you still have other questions,please let me know.
I configured a stack for a NodeJS application server using Amazon OpsWorks.
I need to access some environment variables which define Google API credentials. How can I achieve this ? I already spent more two days on this.
I ended up by the following chef recipe :
magic_shell_environment "GOOGLE_CLIENT_ID" do
owner 'root'
group 'root'
value "********"
mode '0600'
end
I use the root account because it seems the NodeJS is run under that account. If I remove the owner and group attributes, I can read those environment variables fine (as the default ubuntu user). However, when I ssh to my instance and type echo $GOOGLE_CLIENT_ID as root, I get an empty string.
Also, where is logged the output of console.xxxx(...) ?
OpsWorks now lets you specify up to 20 custom environment variables in the app settings page. In the case of a node.js app these will be available in the process.env object.
This should be fairly easy to do. Just add the following line to the top of your recipe.
ENV['GOOGLE_CLIENT_ID']="YOUR_CLIENT_ID"
Use the OpsWorksEnvy cookbook. It hooks nicely into the default nodejs cookbooks and lets you set the environment variables in your stack attributes.
What's a possible way to determine on an Azure website with multiple instances what instance is responding (some ID or other piece of unique info)?
The following environment setting will have the instance id the current request is running on: WEBSITE_INSTANCE_ID.
You'll also receive this id as a cookie in the response named: ARRAffinity.
You can also use this information to get back to that specific instance, see: http://blog.amitapple.com/post/2014/03/access-specific-instance/ for more information about it.
Microsoft Azure provides many environment variables for Azure Web Apps (formerly known as Website), including the following:
WEBSITE_SITE_NAME - the name of the site.
WEBSITE_INSTANCE_ID- the id representing the VM that the site is running on.
etc
See Azure Runtime Environment by David Ebbo for more details.
You can use Server.MachineName to get the name of the server.
2022-06-06
Configuration of Web App
How to find Instance
1.This is an instance ID.
2.Go to see the environment
3.Find which variable is pl1sdlwk0001WS, and COMPUTERNAME is that you want.
Set up InstanceInputEndpoint in configuration. This will allocate ports from the given port range for each instance, then you can visit a instance through the port.
For more information about InstanceInputEndpoint: http://msdn.microsoft.com/en-us/library/windowsazure/gg557553.aspx
You can use RoleEnvironment.CurrentRoleInstance.Id
Request.ServerName I believe. Just like vanilla IIS
I have to configure one of the module in my application and give it a specific URL, based on the hostname. Something like http://localhost locally and http://myapp.herokuapp.com. I know I can just hardcode the value depending on NODE_ENV, or even store it as an environment value and use process.env.CUSTOMVAR_HOSTNAME. But somehow it feels wrong, since myapp is already configured in the Heroku admin panel. And I can't use request.headers.host since the module configuration happens at the start of the application, before any request can be handled.
Is there a way to retrieve the Heroku application name from the code ? Or from an environment variable ? I want my code to stay the same whether I'm executing code locally or on Heroku (or any other place actually).
I didn't find any way, so I created a local variable hostname based on NODE_ENV (development or production) with the proper hostname value.