How can I copy a "Microsoft.Web/sites/slots" appsettings values into a file? - azure-pipelines-release-pipeline

Using an ARM template, I populate new and existing secrets from a keyvault (and a few environment specific settings) into the appsettings for a staging slot.
As part of the release pipeline I overwrite some of the appsettings on a slot with test values using the az webapp config appsettings set command.
After this, I need to revert the appsettings back to the original values from the ARM template prior to swapping my slot with the production slot.
Can I directly copy the slot's appsettings to a file in the pipeline, or create an additional file in the ARM template?
This would allow me to reapply the production settings after I run my tests.

Can I directly copy the slot's appsettings to a file in the pipeline, or create an additional file in the ARM template?
Of course, you can achieve it.
You could try to use the following command to output the appsettings to the Json file.
$result=az webapp config appsettings list --name WebAppName -g ResourceGroupName --slot slotname
$result | Out-File "$(System.DefaultWorkingDirectory)\file.json"
Then the appsettings will be output to the json file.
For example:
After running the test, you could run the following command to revert the appsettings back to the original values.
az webapp config appsettings set -g ResourceGroupName -n WebAppName --slot slotname --settings "#$(System.DefaultWorkingDirectory)\file.json"
Here is the doc about az web app config settings.

Related

Self hosted Github runner does not load env variables from .zshrc

When I'm trying to run an action via Github with my self hosted runner it is not possible to load the environment variables from my .zshrc file (e.g. the PATH)
When I'm executing "printenv" I will get e.g for PATH:
PATH=/usr/bin:/bin:/usr/sbin:/sbin
but it should be:
PATH=/Users/jenkins/.rbenv/shims:/opt/homebrew/opt/openjdk/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/jenkins/.rbenv/shims:/opt/homebrew/opt/openjdk/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/bin:/bin:/usr/sbin:/sbin
It is only possible when I call source ~/.zshrc before the printenv.
Is it possible to open the shell directly with the zshrc env variables without sourcing it manually?

az webapp deployment source config choose solution file

I am trying to deploy an app using the following:
az webapp deployment source config --branch master --manual-integration --name myapp --repo-url https://$GITUSERNAME:$GITUSERPASSWORD#dev.azure.com/<Company>/Project/_git/<repo> --resource-group my-windows-resources --repository-type git
The git repo contains 2 .sln solution files and this causes an error when attempting to deploy. Is there any way I can specify which solution file to use? I can seem to find a way in the docs but wondered if there might be a workaround.
I found a solution where you create a .deployment file in the root of the solution with these contents
[config]
project = <PATHTOPROJECT>
command = deploy.cmd
Then a deploy.cmd
nuget.exe restore "<PATHTOSOLUTION>" -MSBuildPath "%MSBUILD_15_DIR%"
The -MSBuildPath may be optional for you

need help to build and deploy ssis packages to Integration Services catalog

I was following this interesting post regarding building SSIs project on Devops.
Continuous Integration for BI in VSTS: Splitting Build Steps by Project Type
Building worked fine, but I also need to deploy the ispac file to either local Integration Services catalog or on an Azure SQL DB integration catalog.
The ssisbuild tool can be used in a PowerShell task on Azure Devops and building works fine. But when I try using ssisdeploy I got problems.
here is my code (I use nuget tasks to download SSISBuild so it can be run on building and deploy. Below you see my code. Actually I don't need to find all ispac files since I just have one SSIS project. Hope any one can help me out here
Regards Geir
Get-ChildItem -Filter *.ispac -Recurse | Where-Object { -Not ($_.FullName -match "obj") } | ForEach-Object {
&"$($env:BUILD_SOURCESDIRECTORY)\SSISBuild.2.3.0\tools\ssisdeploy" $_.FullName -Catalog SSISDB -Folder Test -ProjectName Testproject
if ($LASTEXITCODE -ne 0) {
throw "Build failed.";
}
}
I usually follow these steps on SSMS to deploy and schedule my SSIS Package on server:
1. Create a Catalog inside Integration Services-Catalog.
2. Right click on this new Catalog and create a new folder inside it
3. After creating the folder you will have two sub-folders automatically created (Projects and Environment).
Now Right click on the Project folder and add a project to it (from file system directory).
After this you can use SQL Server-Agent to add a new job and use the above added catalog
For deploying you need more values like Server, Username, Password etc.
take a look on https://www.nuget.org/packages/SSISBuild/#
A command line utility that deploys an SSIS deployment package to an SSIS catalog.
Syntax:
ssisdeploy [Ispac File] -ServerInstance <ServerInstanceName> -Catalog <CatalogName> -Folder <FolderName> -ProjectName <ProjectName> [-ProjectPassword <ProjectPassword>] [-EraseSensitiveInfo]
Switches:
Ispac File:
Full path to an SSIS deployment file (with ispac extension). If a deployment file is not specified, ssisdeploy searches current working directory for a file with ispac extension and uses that file.
-ServerInstance:
Required. Full Name of the target SQL Server instance.
-Catalog:
Name of the SSIS Catalog on the target server. If not supplied, then SSISDB value is used.
-Folder:
Required. Deployment folder within destination catalog.
-ProjectName:
Name of the project in the destination folder. If not supplied, then deployment file name is used.
-ProjectPassword:
Password to decrypt sensitive data for deployment.
-EraseSensitiveInfo:
Option to remove all sensitive info from the deployment ispac and deploy all sensitive parameters separately. If not specified then sensitive data will not be removed.
Example:
ssisdeploy.exe sample.ispac -ServerInstance dbserver\instance -Catalog SSISDB -Folder SampleFolder -ProjectName Sample -ProjectPassword xyz -EraseSensitiveI

How to setup multiple environments (dev\stage\production) with elastic beanstalk?

I need to do the following
Change environment variables according to the published env. Set Set up cron jobs according to the dev. I I would like to run just 1 command line "eb deploy dev" or something similar.
Use setenv
You can set environment variables with setenv. These will then be remembered for that environment.
More details: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-setenv.html
Example
For example, suppose you have created an EB environment called 'staging' and you want to set the variable DB to 'localhost', you can use:
eb setenv DB=localhost -e staging
Crons
Now that you have a different environment variables, you can check them in a script etc. to decide if the cron should be set up.
Note that the crons may not actually have access to your environment variables so you need to set those again for the cron while setting up the cron.
This is my solution to the problem, it took some time to setup but now i can do all the changes with 1 command line.
Make your own folder with all the files for all the environments.
In .ebextensions folder setup empty config files for eb.
npm runs a script named "deploy.js" together with the flag of the specific env.
The script will do the following
copy the requested env data to the empty files according to the env
git stash the changes of .ebextensions folder (eb deploys using git)
eb use env
eb deploy
So now i can tun npm run deploy:dev and everything runs

VSTS Deploy IIS App winrm and change appsettings.json

I am deploying an IIS app on another machine using the "Deploy IIS App winrm" task.
This task deploys the zip file. In this zip there is an appsettings.json with variables preceding and ending with underscores.
I need to replace values in the appsettings.json for each environment.
I tried putting the json file as "Web deploy parameter file" and "Overide parameters" but this doesn't work. How can I change the appsettings.json?
You don’t need to change appsettings.json. The core project can retrieve data from appsettings.[environment].json file per to ASPNETCORE_ENVIRONMENT environment variable.
For example:
Add corresponding appsettings.[environment].json files to project, such as appsettings.Production.json, appsettings.Development.json and set the corresponding value in each files.
Code in Startup file
:
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
Set/add ASPNETCORE_ENVIRONMENT environment variable to each environment machine (just need to set/add once)
There are some articles that can help you:
Configuration in ASP.NET Core
Working with multiple environments
If you still want to change appsettings.json file, you can unzip packaged file, then update file by using Token task (e.g. Replace Tokens), then zip these files.
More information, you can refer to Managing Config for .NET Core Web App Deployments with Tokenizer and ReplaceTokens Tasks