Substitute Variables in web.config outside of appsettings, or connectionstring - octopus-deploy

The web.config in my nupkg file outputs the following:
<host>
<baseAddresses>
<add baseAddress="#{Url.AccountService}"/>
</baseAddresses>
</host>
According to Octopus' documentation on Substitute variables in files, the syntax above should be ok as long as I have the variable defined in my project. Which, I do.
I'm also deploying this package only to the DEV environment at this time.
Also, in the Deploy Website step, Under Substitute Variables in Files > I have web.config added to the list of files to perform the substitution on.
However, when the deployment goes through, octopus doesn't substitute this variable with the intended value. What am I doing wrong?

Per our conversation above and things you have tried.
This is the only remaining idea I have for an answer for you:
The documentation Substitute Variables in Files states:
You need to state the full path of the file, relative to the installation directory. So, if you need to replace variables on a file called app.config that is inside of a configfolder on the root of your package, you need to put config\app.configon the Target files field.
It is possible that Octopus Deploy cannot find the file that you are stating requires variable substitution. Everything else about your examples and code looks correct.

Related

How to rename .env variables in package.json?

What I have
I have multiple projects using Percy for Cypress where I set the PERCY_TOKEN env variable inside the .env file. The token is different for each project. In the CI I set different env variables for each project, but locally I have to do it in the .env file. Because of this, I have to edit the .env file whenever I change between projects.
Goal
I would like to set them in the .env file this way:
PROJECT_A_PERCY_TOKEN=tokenhash1
PROJECT_B_PERCY_TOKEN=tokenhash2
So later I could rename these variables to PERCY_TOKEN, eliminating the need to constantly change the .env file.
What I tried
I'm trying to do this inside the package.json file's scripts property. Unfortunately echo $PROJECT_A_PERCY_TOKEN prints nothing. I know that I could create a shell/python/js script that parses the .env file, then passes the value back or calls npm run directly but I would like to do this without an external script.
Problem
It appears to me that I can't access the env variables inside package.json. Is there a way to rename the variable only using the npm script?
tl;dr
If the package you try to configure has the ability to do configuration via a JavaScript file, you can add the renaming at the beginning of it:
process.env.PERCY_TOKEN = process.env.CYPRESS_PERCY_SALESFORCE_TOKEN;
Explanation
While this isn't the solution I was looking for, it is a workaround for this specific use case. Percy supports JavaScript config files so I migrated my YAML config file, then I logged process.env and the .env file's variables were there, so I just need to copy the correct one. This might work for other packages that support JavaScript config files (or some alternative kind of hook/preloader where custom code can be placed), but if they don't, then the question is still unanswered.

Unable to configure the PATH environment variable in Kudu shell via XDT

I am trying to set the PATH environment variable for a web app I am building in Azure in python. I tried to use something like os.environ.setdefault('PATH', 'pandoc-2.14.1-1-amd64.deb') locally, however this does not seem to work once uploaded. I have also tried setting the path in the configuration section on the azure portal, but get the following error:
I have seen posts like
setting the webapp %PATH% environment variable in azure.
The post recommends adding a file called applicationHost.xdt to the home/site directory, which should set the PATH variable automatically. However, I am unable to upload applicationHost.xdt to the files in the directory. This is either because the file UI interface no longer exists, or I am unable to access it. Has the ability to upload via the UI been discontinued?
The only other workaround I can think of is to use echo/cat in the Kudu bash shell to create the applicationHost.xdt manually. This is very tricky. Are there any online tools that, given an input of the contents of a file, create the bash script to generate that file from scratch?
You could add a App settings to you web app, like below:
Then, restart your web app, in Kudu console, you could check it.
Note: App setting names must be unique, so when you use PATH as key it is already configured while deploy so while using in App setting from portal use a different Key name.
As a workaround, you can achieve that through an XDT Transform (XML Document Transform).
Yes, you can use echo to create the same. Simple copy paste the content of the file to be inside single quote ' and stream it into the file already created using echo command.
/home>echo '<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<runtime xdt:Transform="InsertIfMissing">
<environmentVariables xdt:Transform="InsertIfMissing">
<add name="FOO" value="BAR" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
<add name="PATH" value="%PATH%;%HOME%\BAR" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
</environmentVariables>
</runtime>
</system.webServer>
</configuration>' > applicationHost.xdt
Verify the contents using cat command

Is there a way to set non-secret environment variables in Github Actions on the Settings page?

As far as I know, there are two ways to set environment variables in Github Actions:
Hardcoding them into YAML file
Adding them as repository secrets on the settings page
Repository secrets page
But what if I don't want them to be secret? On the picture above, SERVER_PREFIX and ANALYTICS_ENABLED shouldn't be secret. Is there a way to set up env variables on the settings page and make them visible? In Travis we had that option.
There isn't an option to add non-secret ENV variables on GitHub page at now.
You can create workflow-scope ENV variables in workflow step.
env:
SERVER_PREFIX: SOME_PREFIX
Then access by:
${{ env.SERVER_PREFIX }}
If you don't need to use them in the Action's YAML, just define your variables in a downloadable file and then use something like curl or wget to get them into your build environment.
For instance, I've done something similar for common CI files and now I've multiple projects running the same project building scripts, their local action is simply like: download an .sh file, run it.
If you need to set up variables in one of your build steps, to be used later by some other action, have a look at this (but I've never tried it myself).

Why do I get: "--grpc_out: protoc-gen-grpc: The system cannot find the path specified." message?

I am following this C# Quickstart tutorial for gRPC. I have come to this step where I have to use the following command to generate gRPC code:
%UserProfile%\.nuget\packages\Grpc.Tools.1.15.0\tools\windows_x86\protoc.exe -I../../protos --csharp_out Greeter --grpc_out Greeter ../../protos/helloworld.proto --plugin=protoc-gen-grpc=%UserProfile%\.nuget\packages\packages\Grpc.Tools.1.15.0\tools\windows_x86\grpc_csharp_plugin.exe
It doesn't work and what I get in the terminal after running commands above is this:
--grpc_out: protoc-gen-grpc: The system cannot find the path specified.
I don't know why the system cannot find the path since I have changed the path in the command so that it points to the files which need to be executed.
I considered the answer by Michael. However, using a different user account was not an option and I couldn't rename my user account since it's an Azure AD user and as such does not have an entry in the Windows list of local users where I would change its folder location in the registry.
The work-around that did it for me was to change the location of the global packages folder.
Can you try passing an absolute path to --plugin=protoc-gen-grpc=?
I had the same error because had cyrillyc symbols in my user folder. Solved by changing path to global nuget packages in nuget file config (for Windows: %appdata%\NuGet\NuGet.config):
<configuration>
<config>
<add key="globalPackagesFolder" value="D:\.nuget\packages" />
</config>
</configuration>
Instead of D:\.nuget\packages you can set any path without wrong symbols
I ran into the same problem, and with this error "path not found" and your name containing special characters as well, I suspected an issue with non ASCII paths!
It happened that my windows username had a special character "ë" in it
You should create a github issue, but here are some quick fixes:
2 solutions here to fix the issue
Create a new user without special characters and use this account
Harder and dangerous path, but what I've done myself: rename your user account to remove special characters using the following method https://winaero.com/blog/rename-user-profile-folder-windows-10/

How can I track system-specific config files in a repo/project?

I have a ruby project, and the database host and port might be different on dev and production. I need a way to get different values for those into my scripts for the two environments.
The project should be complete - so there should be some way to specify default values. I don't want a clone to be missing the config files. So ignoring them completely won't work.
How do you solve this problem with git?
I would recommend using:
a template config file (a file with variable name in place of the host and port value)
a script able to replace those variable names with the appropriate values depending on the environment (detected by the script)
The Git solution is then a git attribute filter driver (see also GitPro book).
A filter driver consists of a clean command and a smudge command, either of which can be left unspecified.
Upon checkout, when the smudge command is specified, the command is fed the blob object from its standard input, and its standard output is used to update the worktree file.
Similarly, the clean command is used to convert the contents of worktree file upon check-in.
That way, the script (managed with Git) referenced by the smudge can replace all the variables by environement-specific values, while the clean script will restore its content to an untouched config file.
When you checkout your Git repo on a prod environment, the smudge process will produce a prod-like config file in the resulting working tree.

Resources