Search code examples
azureazure-app-service-plansazure-devops-pipelinesazure-yaml-pipelines

Azure App Service Problem in DevOps Pipeline


Hi does anyone have any idea on why im getting this error:

Got service connection details for Azure App Service:'nsclassroomstudent-dgyn27h2dfoyo'
##[debug][POST]https://login.windows.net/***/oauth2/token/
##[debug][GET]https://management.azure.com/subscriptions/237bc9da-22ad-49ea-8411-6cf6a190c18f/resourceGroups/ClassroomInTheCloud/providers/Microsoft.Web/sites/nsclassroomstudent-dgyn27h2dfoyo/?api-version=2016-08-01
##[debug]Correlation ID from ARM api call response : c3eefa7c-9088-44f1-8dc8-dccd7a9f8c4c
##[debug]Processed: ##vso[task.logissue type=error;code=ResourceNotFound;]
##[debug]Deployment Failed with Error: Error: Failed to fetch App Service 'nsclassroomstudent-dgyn27h2dfoyo' details. Error: The Resource 'Microsoft.Web/sites/nsclassroomstudent-dgyn27h2dfoyo' under resource group 'ClassroomInTheCloud' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix (CODE: 404)
##[debug]task result: Failed

My code is attached, I have been through the microsoft Site: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-app-service-settings?view=azure-devops

I have added the Connected Service Name to my YAML but I still get the error and im not sure what else it wants.

Thanks

#pool:
 # vmImage: windows-latest
resources: 
  repositories: 
  - repository: Student
    name: Classroom In The Cloud/Student
    path:
    - include: /Student/Student 
    type: git 
    ref: master #branch name

variables: 
  System.Debug: true
  azureSubscription: 'azuresubscription'
  RG: 'ClassroomInTheCloud'
  Location: West Europe 
  containername: 'private'
  appconnectionname: 'RunPipelinesInOtherSubscription'
  
jobs:
- job: job1
  displayName: Create And Publish Artifact
  pool:
    vmImage: vs2017-win2016
  steps:
  - checkout: Student
    clean: true

  - task: DotNetCoreCLI@2
    displayName: dotnet restore
    inputs:
      command: restore
      projects: '**/*.csproj'

  - task: DotNetCoreCLI@2
    displayName: dotnet build
    inputs:
      projects: '**/*.csproj'
      workingDirectory: Student

  - task: DotNetCoreCLI@2
    displayName: dotnet publish
    inputs:
      command: publish
      projects: '**/*.csproj'
      arguments: --output "$(Build.ArtifactStagingDirectory)"
      zipAfterPublish: true
      modifyOutputPath: false
      workingDirectory: Student

  - task: PublishPipelineArtifact@1
    displayName: Publish Pipeline Artifact
    inputs:
      targetPath: '$(Build.ArtifactStagingDirectory)'
      artifact: 'Student'
      publishLocation: 'pipeline'

- job: job2
  displayName: 'Get Variable Value for Student Env'
  dependsOn: job1
  steps:
  - task: AzureCLI@1
    displayName: 'Azure CLI '
    inputs:
      azureSubscription: $(azureSubscription)
      scriptLocation: inlineScript
      inlineScript: |
        mkdir $(Pipeline.Workspace)\BlobFile
        az storage blob download --container-name $(containername) --file '$(Pipeline.Workspace)/s/student.json' --name 'student.json' --connection-string 'DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=devscriptstorage;AccountKeyMY VALUE HERE'

  - pwsh: |
      cd '/home/vsts/work/1/s/'
      ls
      $armOutput = Get-Content '/home/vsts/work/1/s/student.json' | convertfrom-json
      $student = $armOutput.studentvalue #use student not studentvalue
      $type = $armOutput.type
      $appServicePlanName = $armOutput.appServiceValue
      Write-Host "The value of [$student] is [$appServicePlanName]"
      Write-Host "##vso[task.setvariable variable=studentvalue;isOutput=true]$student" #use studentvalue not $studentvalue
      Write-Host "##vso[task.setvariable variable=appServiceValue;isOutput=true]$appServicePlanName" #use appServiceValue not $appServicePlanName
    name: setvarStep

  - script: echo $(setvarStep.studentvalue)
  - script: echo $(sevarStep.appServiceValue)
    name: echovar

- job: job3
  displayName: Create Web App 
  dependsOn: job2
  variables:
    webappname: $[ dependencies.job2.outputs['setvarStep.studentvalue'] ]
    appservice: $[ dependencies.job2.outputs['setvarStep.appServicevalue'] ]

# Download Artifact File
  steps: 
  - download: none
  - task: DownloadPipelineArtifact@2
    displayName: 'Download Build Artifacts'
    inputs:
      patterns: '**/*.zip'
      path: '$(Build.ArtifactStagingDirectory)'

  # deploy to Azure Web App 
  - task: AzureWebApp@1
    inputs:
      package: $(Build.ArtifactStagingDirectory)/**/*.zip 
      azureSubscription: $(azureSubscription)
      appName: '$(webappname)'
      ResourceGroupName: $(RG)  

  - task: AzureAppServiceSettings@1
    inputs:
      azureSubscription: $(azureSubscription)
      ConnectedServiceName: $(appconnectionname)
      appName: '$(webappname)'
      resourceGroupName: $(RG)
      # To deploy the settings on a slot, provide slot name as below. By default, the settings would be applied to the actual Web App (Production slot)
      # slotName: staging
      appSettings: |
        {
          "name": "DIAGNOSTICS_AZUREBLOBCONTAINERSASURL",
          "value": "VALUEINHERE",
          "slotSetting": false
        },
        {
          "name": "DIAGNOSTICS_AZUREBLOBRETENTIONINDAYS",
          "value": "365",
          "slotSetting": false
        },
        {
          "name": "OEM",
          "value": "netsupport",
          "slotSetting": false
        },
        {
          "name": "SCM_REPOSITORY_PATH",
          "value": "d:\\home\\respository",
          "slotSetting": false
        },
        {
          "name": "VIDEO_CLIENT_URL",
          "value": "https://signal-uks.classroom.cloud",
          "slotSetting": false
        },
        {
          "name": "WEBSITE_NODE_DEFAULT_VERSION",
          "value": "10.15.2",
          "slotSetting": false
        }


Solution

  • I ended up fixing this, when changing app settings on an app you have to put in the app name in the displayname area in the code like so:

    - task: AzureAppServiceSettings@1
      displayName: 'Azure Web App Deploy: $(webappname)'
        inputs:
          azureSubscription: $(azureSubscription)
          ConnectedServiceName: $(appconnectionname)
          appName: '$(webappname)'
          resourceGroupName: $(RG)
          # To deploy the settings on a slot, provide slot name as below. By default, the settings would be applied to the actual Web App (Production slot)
          # slotName: staging
          appSettings: |
            {
              "name": "DIAGNOSTICS_AZUREBLOBCONTAINERSASURL",
              "value": "VALUEINHERE",
              "slotSetting": false
            },
            {
              "name": "DIAGNOSTICS_AZUREBLOBRETENTIONINDAYS",
              "value": "365",
              "slotSetting": false
            },
            {
              "name": "OEM",
              "value": "netsupport",
              "slotSetting": false
            },
            {
              "name": "SCM_REPOSITORY_PATH",
              "value": "d:\\home\\respository",
              "slotSetting": false
            },
            {
              "name": "VIDEO_CLIENT_URL",
              "value": "https://signal-uks.classroom.cloud",
              "slotSetting": false
            },
            {
              "name": "WEBSITE_NODE_DEFAULT_VERSION",
              "value": "10.15.2",
              "slotSetting": false
            }

    I got to this conclusion after playing around with the classic pipeline editor and watching what it would do to the YAML code.