Azure webapp and and their webjobs deployment - azure-devops

I want to deploy webapp and their webjobs in environments using VSTS ci/cd.
Note:
1.The webapp having three webjobs( WJ1+ (WJ2+Its instance(2))
2.The webapp having 6 webjobs( WJ1+ (WJ2+Its instance(5)).
3.its not picking the variables which we aren't adding in release pipeline.
Quick help much appreciated
Thanks,
SP

Web Jobs will not pick the variables from your release pipeline, instead it can get these variables/settings from the web app's appsettings section.
You can do that manually by setting the appsettings for the web app in Azure Portal by following this link https://learn.microsoft.com/en-us/azure/app-service/web-sites-configure
Or you can do it automatically by changing web.config/appsettings using transformation tasks in your release pipeline as instructed in this link
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/transforms-variable-substitution?view=azure-devops
As for the web jobs deployment:
If you added the web jobs from visual studio, it will add a file under the properties folder in your web app called webjobs-list.json. If it is not there, then add it and the content should be similar to:
{
"$schema": "http://schemastore.org/schemas/json/webjobs-list.json",
"WebJobs": [
{
"filePath": "../webjob1.csproj"
},
{
"filePath": "../webjob2.csproj"
},
{
"filePath": "../webjob3.csproj"
}
]
}

Related

Setting Environment Variables using IIS Administration API

Does anyone know how to set environment variables on an application pool using the IIS Administration REST API?
https://learn.microsoft.com/en-us/iis-administration/api/application-pools
Setting environment variables using the Web API isn't currently possible.
If anyone else is interested in this feature, i've created a branch containing a first draft. Maybe i will submit a PR after some testing.
My Branch
You can then create an AppPool like this:
{
"name": "Demonstration App Pool",
"environment_variables": {
"CONNECTION_STRING": "some value"
}
}

FileTransform Task in release pipeline doesn't update the value - AzureDevOps

I'm trying to update the value of appsettings.Development.json file while releasing application using Azure DevOps pipeline.
appSettings.Development.json
{
"Networks": {
"EnableNetwork": {
"SomeNetwork": {
"SomeValue": "Old Value"
}
}
}
}
I have configured File Transform: task as follows
And set the variable with scope "Release"
File Transfer Task runs successfully
However, it doesn't change the value after deployment. Tried different changes as shown in SO answers like How to change Appsettings and Config info in Release Pipeline. But not sure where is the issue!
The steps you use File Transform task should be correct. The value of appsettings.Development.json can be updated successfully.
You can check the log of File Transform task to confirm this point.
For example:
it doesn't change the value after deployment.
From your screenshot, the cause of this issue could be that you are using Microsoft-hosted agent to deploy the IIS WebSite. It will deploy the website to hosted agent instead of your local machine.
According to your screenshot of the release pipeline definition, the Stage 3 should be run on Deployment Group. In this case, it will deploy the package to local machine.
You need to check the release pipeline definition to make sure the stage is running on Deployment Group. Then you will see the changes after deployment.

Synapse - Can't properly deploy SQL linked server

Hello I’m having a problem when I try to deploy my Synapse workspace to another environment (eg. Development to Test).
The problem is that the SQL linked services doesn’t seems to deploy properly. The first screenshot is from the development synapse and the second screenshot form test. As you can see the settings of the linked service are completely different.
Development
Test enviroment
I’m using the standard synapse deployment task in my DevOps pipeline
- task: Synapse workspace deployment#1
displayName: 'Synpase deployment task for workspace: syn$(name)$(environment)'
inputs:
TemplateFile: '$(System.DefaultWorkingDirectory)/$(cicd_synapse_workspace_origin)/TemplateForWorkspace.json'
ParametersFile: '$(System.DefaultWorkingDirectory)/$(cicd_synapse_workspace_origin)/TemplateParametersForWorkspace.json'
AzureSubscription: '${{ parameters.sercon }}'
ResourceGroupName: 'rg-$(name)-$(environment)'
TargetWorkspaceName: syn$(name)$(environment)
OverrideArmParameters: '
-ls_sq_mark_connectionString $(Connectionstring)
Whereby I overwrite the linked service with a variable form the DevOps library (it contains the following code “("Integrated Security=False;Encrypt=True;Connection Timeout=30;Data Source=databaseserver;Initial Catalog=database")”
The thing I noticed when I looked into the JSON file (TemplateForWorkspace.json) that the linked service is defined as follow:
"ls_sq_mark_connectionString": {
"type": "secureString",
"metadata": "Secure string for 'connectionString' of 'ls_sq_mark'"
},
Maybe the problem is, is that it's suddenly a securestring? But i have no idea how to fixed this issue.

Getting release and build numbers from Azure DevOps Release Pipeline to display in website

I would like to be able to display the release number (*1 in pic) and the build number (*2 in pic) in Asp.Net MVC Core website - FOR that specific website, which was built and released with Azure DevOps.
So if I check code in for an MVC website, the build and release process kicks in and deploys the website - and now I want the same website to display "Release xxxxx" in the footer.
It could be in a JSON file, an environment variable or something - as long as I can access it from Asp.Net Core, I am happy.
How can that be achieved?
If you want in the current app that you built and deployed to display the data you can get the values of the variables like each environment variable:
var releaseName = Environment.GetEnvironmentVariable("Release_ReleaseName", EnvironmentVariableTarget.Process);
var buildNumber= Environment.GetEnvironmentVariable("Build_BuildNumber", EnvironmentVariableTarget.Process);
If you want to display the data in an external app:
You can get all the release data with Azure DevOps Rest API. the API for release is Releases - Get Release:
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}?api-version=5.1
You got a big JSON with the release info, including the release name:
{
"id": 205,
"name": "Release-93",
And in the artifact array, you can get the build id (under definitionReference.version.name):
"version": {
"id": "1439",
"name": "TestVars_20190829.1439..11"
So in your Asp.Net MVC Core app just make a GET rest API call and you have all the data.
In addition, you can use the .NET client libraries for Azure DevOps Services and get the data with GetRelease() method:
string projectName = "TestProject";
VssConnection connection = Context.Connection;
ReleaseHttpClient releaseClient = connection.GetClient<ReleaseHttpClient>();
List<WebApiRelease> releases = releaseClient.GetReleasesAsync(project: projectName).Result;
int releaseId = releases.FirstOrDefault().Id;
// Show a release
WebApiRelease release = releaseClient.GetReleaseAsync(project: projectName, releaseId: releaseId).Result;
// Now get the release name and build nubmer
The solution seems to be to use a plugin for Azure Devops during build Replace Tokens, which replaces strings in a .config file during build/release - and then access those values from the code at runtime.
It is described here in more detail: .NET Core App - How to get build number at runtime

Azure DevOps Release changing appsettings.json Logging section

I have a problem regarding Azure DevOps and release management. First a little background - we use visualstudio.com along with build agents, release agents (running on different environment VMs) to manage our CI, builds, and releases. I am trying to troubleshoot logging on my non-development servers and have traced the problem back to missing elements in my appsettings.json file. When I log into my production VMs and look at the appsetings.json file, I found that my Logging section looked like this:
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Information"
}
},
While within my appsettings.json file within my build artifacts (the website .zip file) looks like this:
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
My logging issues are fixed when I go on the server and change the appsettings.json Logging section to match what is should be according to the appsettings in the build .zip.
My question is - what is it within the Azure DevOps release pipeline (formerly VSTS) that is changing the appsettings.json Logging section? I have verified that my release definition has no variable substitutions for the logging section.
This looks very much like your build is taking the wrong sources. Is it possible that the wrong appsettings.json that you're seeing reflects an outdated version? I don't know why this happens, but I've seen this a couple of times in the past both with Git and TFVC.
If this is the issue, then cleanup your agent working folders or select (once or permanantly) cleanup in the build definition:
Found the problem (and its a silly one). The problem ended being multiple declarations of the Logging section in the appsettings.json file. The declaration at the bottom of the file has:
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Information"
}
},
which would match whats getting deployed.