Yaml deploy succeeding but using wrong ASPNETCORE_ENVIRONMENT

524 views Asked by At

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.

1

There are 1 answers

4
Leo Liu On

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:

enter image description here

Add an app setting in the "App settings" section:

enter image description here

So, what you are doing now is correct.