Yaml deploy succeeding but using wrong ASPNETCORE_ENVIRONMENT - azure-devops

I'm working on a yaml deployment. I am trying to define the aspnetcore_environment. I have tried two ways. One is in the yaml file itself (see below), and the other is in the pipeline variables. Neither seem to work. Luckily I managed to solve it by adding the variables directly to the application settings in azure itself. But I would think I should be able to set this from the yaml deployment file. Well that's my question if it's possible.
It is a .net 6.0 mvc asp.net project. The project is a App Service in azure. It is my first time attempting to do a yaml deployment and this is what I've gotten so far.
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
ASPNETCORE_ENVIRONMENT: 'Acceptance'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '**\[project folder]\*.csproj'
vsVersion: '17.0'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="[app service name]"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PublishPipelineArtifact#1
inputs:
targetPath: $(build.artifactStagingDirectory)
artifact: 'drop'
publishLocation: 'pipeline'
- task: DownloadPipelineArtifact#2
inputs:
buildType: current
artifactName: 'drop'
targetPath: $(Pipeline.Workspace)/drop
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: '[subscriptionName]'
appType: 'webApp'
WebAppName: '[AppserviceName]'
packageForLinux: '$(Pipeline.Workspace)/drop/*.zip'
This page told me how to set the ASPNETCORE_ENVIRONMENT setting.

Yaml deploy succeeding but using wrong ASPNETCORE_ENVIRONMENT
When you define the aspnetcore_environment in the yaml file itself or in the pipeline variables, it could only be used for current pipeline instead of your the application.
That is the reason why why none of them work. You could add a command line task to echo this variable: echo $(ASPNETCORE_ENVIRONMENT).
To use the aspnetcore_environment for your application, you should define your own environment variable, click to your site → All Settings → Application settings:
Add an app setting in the "App settings" section:
So, what you are doing now is correct.

Related

How can I trigger my build on Azure DevOps using YAML file?

How can I trigger my build on Azure DevOps using YAML file?
I did a merge on my master branch. Build was tiggered.
Then I did a pull request from master to
release/development
release/staging
release/production
in this order. Only the merge on release/production triggered the build.
Why? To make sure it is not just a question of the correct version of the YAML file on the correct branch I repeated these actions a second time. Same result.
# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4
trigger:
branches:
include:
- master
- release/production
- release/development
- release/staging
pool:
name: Hosted VS2017
demands:
- msbuild
- visualstudio
- vstest
name: $(Date:yy).$(Date:MM).$(Rev:r)
variables:
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
displayName: 'Use NuGet 4.4.1'
inputs:
versionSpec: 4.4.1
- task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
restoreSolution: $(Solution)
- task: VSBuild#1
displayName: 'Build solution'
inputs:
solution: $(Solution)
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
- task: VSTest#2
displayName: 'Test Assemblies'
inputs:
testAssemblyVer2: |
**\$(BuildConfiguration)\*test*.dll
!**\obj\**
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
diagnosticsEnabled: True
- task: PublishSymbols#2
displayName: 'Publish symbols path'
inputs:
SearchPattern: '**\bin\**\*.pdb'
PublishSymbols: false
continueOnError: true
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
ArtifactName: '$(Parameters.ArtifactName)'
condition: succeededOrFailed()
Why the master and production build are starting and not the other one?
Check if you have set the trigger on the web UI for the build pipeline. The triggers set on the web UI will override that set in the YAML files.
If the triggers set on the web UI only includes the master and release/production branches, the pipeline will only be triggered for the two branches.
To avoid this, you can disable the triggers set on the web UI and only keep the triggers set in the YAML files.
Did you merge yaml to other branches? The build may not start if it is not in a branch. An example of the development branch:

Azure DevOps: Blazor Deployment fails in Pipeline Build

I have a Blazor WASM Pipeline Release build that was running well until I upgraded to .NET5.
Lately I get the following error: ...\Microsoft.NET.Sdk.BlazorWebAssembly.ServiceWorkerAssetsManifest.targets(68,5): Error MSB4018: The "GenerateServiceWorkerAssetsManifest" task failed unexpectedly. followed by System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\a\1\s\ClientSide\BlazorProject\obj\Release\net5.0\service-worker-assets.js'.
My yaml-file:
trigger:
- main
pool:
vmImage: 'windows-latest'
variables:
solution: '**/BlazorProject.csproj'
solutionSln: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
command: 'restore'
restoreSolution: '$(solutionSln)'
feedsToUse: 'select'
noCache: true
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)/WebClient.zip"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
clean: true
createLogFile: true
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'censored'
appType: 'webApp'
WebAppName: 'nextGenClientTest'
packageForLinux: '$(build.artifactStagingDirectory)/WebClient.zip'
So for some reason I think it cannot find the file service-worker-assets.js, but I don't know why.
For the ones wondering why the structure might be strange: I have a solution file that I use to restore nuget-packges and in this pipeline I just want to build a specific project BlazorProject.csproj (which was working fine until I upgraded to .NET5).
Anyone knows, what's suddenly up with service-worker-assets.js?
Azure DevOps: Blazor Deployment fails in Pipeline Build
There is an issue about it:
Blazor Service Worker Asset Manifest path construction bug
And this issue was moved to the Next sprint planning milestone for future evaluation / consideration. And aspnetcore team will evaluate the request when they are planning the work for the next milestone.
Besides, in order to ensure that you have upgraded your project correctly, please refer to the following documents for some more details:
Update Blazor WebAssembly projects

Publishing Pipeline Artifacts for use in another pipeline

I'm trying to publish a couple of pipeline artifacts during a build so that I can use them in a build of another solution.
My first build builds and tests the soltuion using the following yaml
- stage: build_test_release
displayName: Build
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
jobs:
- job: build
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
This all works great and I've been able to do deployments using this yaml in the same file
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'azuresubscription'
appType: 'webApp'
WebAppName: 'webappname'
deployToSlotOrASE: true
ResourceGroupName: 'resourcegroupname'
SlotName: 'staging'
packageForLinux: '$(build.artifactStagingDirectory)/**/projectToPublish.zip'
I'm now trying to publish some of the projects which were build as Pipeline Artifacts so that I can use them in the build of another solution which references them. The following publish task gives me the error:
"##[error]Path does not exist: D:\a\1\a**\projectToPublish.zip"
- task: PublishPipelineArtifact#1
inputs:
targetPath: '$(build.artifactStagingDirectory)/**/projectToPublish.zip'
artifact: 'artifactname'
publishLocation: 'pipeline'
What am I missing here? I've been thinking of moving the projects which are referenced by both soltuions into their own solutions and adding them as nuget packages or something similar. The projects I am trying to publish as artifacts to be used in the second solution are both WCF Client projects.
Thanks!
The issue is that the task you're using, Publish Pipeline Artifacts, does not support wildcards for the 'File or directory path' argument. For this task $(build.artifactStagingDirectory) is replaced with D:\a\1\a\, in the second directory named a Azure DevOps is looking for a sub directory named ** which does not exist and causes the shown error. The other task AzureRmWebAppDeployment#4 you're using does support wildcards.
See the image below, where Azure DevOps shows in the the UI that the PublishPipelineArtifact#1 task does not support wildcards in targetPath:
Second I'm wondering why you're using a wildcard, because the task VSBuild#1 will just drop the package in the build.artifactStagingDirectory which should make the path $(build.artifactStagingDirectory)/projectToPublish.zip to locate the package.
In AzureRmWebAppDeployment#4 you have
'$(build.artifactStagingDirectory)/**/WebProjectToPublish.zip'
And in PublishPipelineArtifact#1 you have a different name
'$(build.artifactStagingDirectory)/**/projectToPublish.zip'

Deploy legacy .net framework console application to on prem server using Azure DevOps CICD pipeline

I am new to DevOps and CICD pipelines.
I successfully deployed ASP .NET MVC website using Azure DevOps CICD pipeline to my onprem agent/machine using Azure DevOps.
Similarly I want to deploy a console application which can be
ultimately used as scheduled job in windows 'Task Scheduler' or either
as a 'Windows Service'. Right now I am managing these deployments
manually but after seeing the power of DevOps I hope, there could be
really some automated solution for console apps as well.
The applications are built in legacy framework like 3.5 to 4.5, so not .net core apps.
I found lot of online articles which demonstrates deploying webjobs on azure or may be possible for onprem but is it possible for old console apps?
I tried to build a very simple console app in Framework 4.7 and tried to deploy/copy/publish to my onprem machine's shared path. Gave permission to VSTS agent services which are running but copy files and publish artifact tasks are failing. I tried to do it in both CI and CD pipelines but all are failing.
Please review the pipelines and logs and suggest where I am doing wrong or there are any alternatives?
https://dev.azure.com/MSTCsandippatel/DemoConsoleApp
2019-11-05T05:03:52.8436105Z ##[error]Publishing build artifacts
failed with an error: Unable to create directory '\MAHANTAM\Azure
Artifacts\DemoConsoleApp'. Unable to verify the directory exists:
'\MAHANTAM\Azure Artifacts\DemoConsoleApp'. If directory is a file
share, please verify the share name is correct, the share is online,
and the current process has permission to access the share.
CI pipeline 1
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=True /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'DemoConsoleApp'
publishLocation: 'Container'
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=True /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'DemoConsoleApp'
publishLocation: 'Container'
CI pipeline 2
pool:
name: Azure Pipelines
demands:
- msbuild
- visualstudio
steps:
- task: NuGetToolInstaller#0
displayName: 'Use NuGet 4.4.1'
inputs:
versionSpec: 4.4.1
- task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(Parameters.solution)'
vstsFeed: '622d44e2-69d4-4d42-bb91-9d6ddd97f9ba/8eaf9077-829d-4567-93c0-8e0d7973634b'
- task: VSBuild#1
displayName: 'Build solution **\*.sln'
inputs:
solution: '$(Parameters.solution)'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
- task: PublishSymbols#2
displayName: 'Publish symbols path'
inputs:
SearchPattern: '**\bin\**\*.pdb'
PublishSymbols: false
continueOnError: true
- task: CopyFiles#2
displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '$(system.defaultworkingdirectory)'
Contents: '**\bin\$(BuildConfiguration)\**'
TargetFolder: '$(build.artifactstagingdirectory)'
condition: succeededOrFailed()
- task: CopyFiles#2
displayName: 'Copy Files Task'
inputs:
SourceFolder: '$(system.defaultworkingdirectory)'
Contents: '**/**'
TargetFolder: '$(build.artifactstagingdirectory)'
condition: succeededOrFailed()
- task: ArchiveFiles#2
displayName: 'Archive $(Build.BinariesDirectory)'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: DemoConsoleApp'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
ArtifactName: DemoConsoleApp
If you use Agent Pool "Azure Pipelines" for your agent, the deployment will occur on an azure cloud machine which doesn't know anything about your on-premise machines.
You should install a self-hosted agent on-premise and link that to your DevOps and use that for the agent.
https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops

Where can I see the created package in Azure DevOps to upload to the store?

I want to create packages to load to the store.
Here is the YAML so far
trigger:
- master
pool:
vmImage: 'VS2017-Win2016'
variables:
solution: '**/*.sln'
buildPlatform: 'x64'
buildConfiguration: 'Release'
appxPackageDir: '$(build.artifactStagingDirectory)\AppxPackages\\'
steps:
- task: NuGetToolInstaller#0
- task: NuGetCommand#2
inputs:
restoreSolution: '**\*.sln'
feedsToUse: config
nugetConfigPath: 'MyApp.Win10/mynuget.config'
- task: VSBuild#1
inputs:
platform: 'x64'
solution: '**\*.sln'
configuration: '$(buildConfiguration)'
msbuildArgs: '/p:AppxBundlePlatforms="$(buildPlatform)" /p:AppxPackageDir="$(appxPackageDir)" /p:AppxBundle=Always /p:UapAppxPackageBuildMode=StoreUpload'
The docs mention the Artifacts explorer on the Artifacts tab of the builds results page. But I cant find it.
I have also looked at the Artifacts in the project but they only contain some nuget packages I put there.
You don't see the artifacts becuase you don't have the "Publish Build Artifacts" task.
For example, add this task:
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: '$(appxPackageDir)'
artifactName: 'drop'