Azure Pipeline (YAML) deploys an empty solution to my FunctionApp - azure

I'm building a CI-CD azure pipeline with YAML to deploy an azure function app.
Everything works fine, I can even set some properties for the function app, but my function app remains empty.
I downloaded the zip artifact and it looks just fine.
trigger:
- master
variables:
variables:
buildConfiguration: 'Release'
Parameters.RestoreBuildProjects: '**/TestFunction.csproj'
stages:
- stage: Build
jobs:
- job:
pool:
vmImage: 'vs2017-win2016'
continueOnError: false
steps:
- task: DotNetCoreCLI#2
displayName: 'Restore'
inputs:
command: 'restore'
projects: '$(Parameters.RestoreBuildProjects)'
feedsToUse: 'select'
vstsFeed: '/0856b234-f3a6-4052-b5a6-ed9f6ec9c635'
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: '$(Parameters.RestoreBuildProjects)'
arguments: '--configuration $(BuildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'Publish Build'
inputs:
command: publish
arguments: '--configuration $(BuildConfiguration)'
projects: '$(Parameters.RestoreBuildProjects)'
publishWebProjects: false
modifyOutputPath: true
zipAfterPublish: false
- task: ArchiveFiles#2
displayName: "Archive Files"
inputs:
rootFolderOrFile: "$(System.DefaultWorkingDirectory)"
includeRootFolder: false
archiveFile: "$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip"
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip'
ArtifactName: 'drop'
- stage: Deploy
jobs:
# track deployments on the environment
- deployment:
pool:
vmImage: 'vs2017-win2016'
# creates an environment if it doesn’t exist
environment: 'dev'
strategy:
# default deployment strategy
runOnce:
deploy:
steps:
- task: DownloadBuildArtifacts#0
displayName: 'Download Artifacts'
inputs:
buildType: 'current'
downloadType: 'specific'
downloadPath: '$(System.ArtifactsDirectory)'
- task: AzureFunctionApp#1
displayName: 'Azure Function App Deploy: ngproductionfetcherfuncref'
inputs:
azureSubscription: 'Agder Energi Sandbox (1aa9cf92-9d42-49a6-8d31-876ac2dff562)'
appType: functionApp
appName: myFunctionApp
package: '$(System.ArtifactsDirectory)/**/*.zip'
appSettings: '-name0 value0 -name1 value1'
The pipeline is all green:
Got service connection details for Azure App Service:'myFunctionApp'
Updating App Service Application settings. Data: {"WEBSITE_RUN_FROM_PACKAGE":"1"} {"WEBSITE_RUN_FROM_ZIP":{"value":""}}
Updated App Service Application settings and Kudu Application settings.
Package deployment using ZIP Deploy initiated.
Successfully deployed web package to App Service.
Updating App Service Application settings. Data: {"name0":"value0","name1":"value1"} undefined
Updated App Service Application settings and Kudu Application settings.

Related

Azure FunctionApp without functions after successful CI/CD over Azure DevOps

I've created an Azure Function App (Linux) running on an App Service Plan Y1 and have my sources in Azure DevOps Git. The functions are written in C# on DOTNET 6.
Below you can see my YAML definitions for the CI and a separated CD pipeline. When I execute the pipeline everything works well (both are green). After the deployment however this is how my Azure Portal looks in the Functions blade:
Using the VS Code Azure Extension and looking into the files of the function app I get:
When I look in the artifact of the CI pipeline everything looks good (explorer view of the downloaded zip):
The bin-folder is populated there.
Some key points:
I have no slots in the function app.
The deployments are visible in the associated App Insights.
My reference point is Microsoft Learn
So is it normal to get the 404 when searching in VS code and did somebody experience something similar or even know the solution?
Sidenote:
I used to deploy my function using VS Code with extensions install. Today I now get a weired error message after the deployment:
CI YAML
pool:
vmImage: 'ubuntu-latest'
trigger: none
variables:
- name: 'Solution'
value: '**/MyProject.sln'
- name: 'ProjectFilter'
value: '**/*.csproj'
- name: 'BuildConfiguration'
value: 'Release'
steps:
- task: UseDotNet#2
displayName: Use DotNet 6
inputs:
version: '6.0.x'
- task: DotNetCoreCLI#2
displayName: Restore
inputs:
command: restore
projects: '$(ProjectFilter)'
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: '$(ProjectFilter)'
arguments: '--no-restore --configuration $(BuildConfiguration)'
- task: DotNetCoreCLI#2
displayName: Publish Image Converter
inputs:
command: publish
projects: src/Functions/**/MyProject.csproj
publishWebProjects: false
arguments: '--no-restore --no-build --configuration $(BuildConfiguration) --output $(Build.DefaultWorkingDirectory)/function_publish_output'
zipAfterPublish: false
- task: ArchiveFiles#2
displayName: Archive Image Converter
inputs:
rootFolderOrFile: '$(Build.DefaultWorkingDirectory)/function_publish_output'
includeRootFolder: false
archiveFile: '$(Build.ArtifactStagingDirectory)/MyProject.zip'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
condition: succeededOrFailed()
CD YAML
variables:
- name: 'vmImageName'
value: 'ubuntu-latest'
- name: 'serviceConnectionName'
value: 'MYCONN'
- name: 'project'
value: 'MYPROJECT'
resources:
pipelines:
- pipeline: ci
source: 'NAMEOFCI'
trigger: true
pool:
vmImage: $(vmImageName)
trigger: none
stages:
- stage: Production
displayName: Production
jobs:
- deployment: Deploy
displayName: 'Deploy'
environment: 'Production'
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- download: ci
displayName: 'Download Artifact'
artifact: drop
- task: AzureFunctionApp#1
displayName: 'Deploy Image Converter Function'
inputs:
azureSubscription: '$(serviceConnectionName)'
appType: functionAppLinux
appName: 'fapp-**********-prod'
package: '$(Pipeline.Workspace)/ci/drop/MyProject.zip'
runtimeStack: 'DOTNET|6.0'
Can you check what exactly you see on the file system? You can use console or Advanced tools:

Deploy to AzureDevOps - Error: Failed to get App service 'xxx' application settings

I want to deploy a Static Web App. Build and deploy stages are specified in azure-pipeline. The pipeline fails when it comes to AzureAppServiceSettings#1 task. That is what I got in log:
Got service connection details for Azure App Service:'xxx-dev-app'
Trying to update App Service Application settings. Data: {"testDb":"test"}
##[error]Error: Failed to get App service 'xxx-dev-app' application settings. Error: The Resource 'Microsoft.Web/sites/xxx-dev-app' under resource group 'xxx-dev-rg' was not found.
The task in azure-pipeline is:
- task: AzureAppServiceSettings#1
displayName: Azure App Service Settings
inputs:
azureSubscription: 'ServiceConnectionName'
appName: 'xxx-dev-app'
resourceGroupName: 'xxx-dev-rg'
appSettings: |
[
{
"name": "testDb",
"value": "test",
"slotSetting": false
}
]
DevOps has a Contributor access level both in the app and resource group.
Any suggestions what causes deployment failure?
I added a task for artifact downloading as it was proposed by #Daniel Mann, and it worked:
trigger:
- master
pool:
vmImage: ubuntu-latest
variables:
buildConfiguration: 'Release'
stages:
- stage: Build
jobs:
- job: Build
displayName: 'Build'
steps:
- task: DotNetCoreCLI#2
inputs:
command: 'build'
configuration: 'Release'
arguments: --output $(System.DefaultWorkingDirectory)/publish_output --configuration $(buildConfiguration)
- task: ArchiveFiles#2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/publish_output'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- stage: Test
dependsOn: Build
condition: succeeded()
jobs:
- job: Deploy
displayName: 'Deploy to Test'
steps:
- download: current
artifact: drop
- task: AzureWebApp#1
inputs:
azureSubscription: 'yyy'
appType: 'webApp'
appName: 'xxx'
package: '$(Pipeline.Workspace)/drop/*.zip'

Azure Release Pipeline IISVirtualDirectory YAML

I'm having this Release created via Azure and its working perfectly. I have create the pipeline using YAML and i want to put the release in the same file. I'm using the "View YAML" approach for this to copy the YAML template and use it. But somehow its failing with this message:
ERROR ( message:Cannot find APP object with identifier "TEST01/". )
##[error]Process 'appcmd.exe' exited with code '1168'.
I guess im missing some other parameters or i really can't figure out how to use the same approach using YAML.
This is the code:
trigger:
- develop
stages:
- stage:
jobs:
- job: Build
displayName: Agent job 1
pool:
vmImage: ubuntu-latest
steps:
- checkout: self
- task: ArchiveFiles#2
displayName: Archive $(System.DefaultWorkingDirectory)
inputs:
rootFolderOrFile: "$(System.DefaultWorkingDirectory)"
includeRootFolder: false
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
- stage:
jobs:
- job: Deploy
displayName: Deploy to IIS Dev
pool:
vmImage: windows-2019
steps:
- task: IISWebAppManagementOnMachineGroup#0
displayName: 'IIS Web App Manage'
inputs:
IISDeploymentType: iISVirtualDirectory
ParentWebsiteNameForVD: TEST01
VirtualPathForVD: /admin/test
PhysicalPathForVD: '%SystemDrive%\inetpub\_phpapps\test-center'
- task: IISWebAppDeploymentOnMachineGroup#0
displayName: 'IIS Web App Deploy'
inputs:
WebSiteName: "TEST01"
VirtualApplication: "/admin/test"
TakeAppOfflineFlag: True
XmlVariableSubstitution: True
After some research and testing seams like there is a new approach regarding deployment/releases.
Instead of using "Pipelines > Release" and create a release, if you are using the Yaml approach (defining stages etc.) you need to use it with "Environments". Create the group or environment and use it.
Two steps here are missing, one is the package and the other is env, where should be deployed.
So the solution for the above code is the following:
- stage: 'DeployTest'
displayName: 'DeployTest'
dependsOn: 'Build'
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'develop'))
jobs:
- deployment: Test
displayName: Test
environment:
name: 'ENV-TEST-GROUP'
resourceType: VirtualMachine
strategy:
runOnce:
deploy:
steps:
- task: IISWebAppManagementOnMachineGroup#0
displayName: 'IIS Web App Manage'
inputs:
IISDeploymentType: iISVirtualDirectory
ParentWebsiteNameForVD: TEST01
VirtualPathForVD: /admin/test
PhysicalPathForVD: '%SystemDrive%\inetpub\_phpapps\test-center'
- task: IISWebAppDeploymentOnMachineGroup#0
displayName: 'IIS Web App Deploy'
inputs:
WebSiteName: "TEST01"
VirtualApplication: "/admin/test"
Package: $(Pipeline.Workspace)\drop\build_test.zip
TakeAppOfflineFlag: True
XmlVariableSubstitution: True

Azure DevOps - Deployment problems

I am trying to deploy a new code in an existing function on Azure but for some reason I am getting a Green/Pass pipeline but when I request the URL I got error 404.
What I have done:
Setup the function manually
Run a Pipeline with the stages:
a) mvn package
b) zip content of azure functions in the target
c) Deploy artifact from agent to the pipeline
d) Deploy artifact into a function using snipped code from microsoft.
The pipeline gets a green state and the function has been deployed:
Starting: AzureFunctionApp
==============================================================================
Task : Azure Functions
Description : Update a function app with .NET, Python, JavaScript, PowerShell, Java based web applications
Version : 1.195.0
Author : Microsoft Corporation
Help : https://aka.ms/azurefunctiontroubleshooting
==============================================================================
Got service connection details for Azure App Service:'test'
Trying to update App Service Application settings. Data: {"WEBSITE_RUN_FROM_PACKAGE":"https://teststorage.blob.core.windows.net/azure-pipelines-deploy/package_1639741028399.zip?***"}
Updated App Service Application settings.
Updated WEBSITE_RUN_FROM_PACKAGE Application setting to https://teststorage.blob.core.windows.net/azure-pipelines-deploy/package_1639743928399.zip?***
Syncing triggers for function app
Sync triggers for function app completed successfully
Successfully added release annotation to the Application Insight :test
App Service Application URL: http://test.azurewebsites.net
Finishing: AzureFunctionApp
but when I request the URL it fails, also I check the functions section in the portal , and the function that was there (deployed manually) got removed.
Note:
The code is fine because I can deploy manually the same code and it is working fine, via pipeline is not working.
Pipeline code:
pool:
vmImage: ubuntu-latest
variables:
serviceName: test
jdkVersion: "1.11"
stages:
- stage:
displayName: Build
jobs:
- job: "Deployment_draft"
steps:
- task: MavenAuthenticate#0
displayName: "Maven Authenticate"
inputs:
artifactsFeeds: test-artifactory
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: $(Build.SourcesDirectory)/${{ variables.serviceName }}/target/azure-functions/${{ variables.serviceName }}
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: '${{ variables.serviceName }}'
publishLocation: 'Container'
- task: AzureFunctionApp#1
inputs:
azureSubscription: 'SubscriptionTest(Subscription ID)'
appType: 'functionAppLinux'
appName: 'test'
deploymentMethod: zipDeploy
package: '$(Build.ArtifactStagingDirectory)/**/*.zip'
rootFolderorFile - Enter the root folder or file path to add to the archive. If a folder, everything under the folder will be added to the resulting archive. Default value: $(Build.BinariesDirectory)
I have slightly modified your pipeline.
pool:
vmImage: ubuntu-latest
variables:
serviceName: test
jdkVersion: "1.11"
stages:
- stage:
displayName: Build
jobs:
- job: "Deployment_draft"
steps:
- task: MavenAuthenticate#0
displayName: "Maven Authenticate"
inputs:
artifactsFeeds: test-artifactory
- stage : deploy
jobs:
- job:
displayName : Function App update
steps:
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(Build.SourcesDirectory)'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
ArtifactName: '${{ variables.serviceName }}'
publishLocation: 'Container'
- task: AzureFunctionApp#1
inputs:
azureSubscription: 'SubscriptionTest(Subscription ID)'
appType: 'functionAppLinux'
appName: 'test'
deploymentMethod: zipDeploy
package: '$(Build.ArtifactStagingDirectory)/**/*.zip'
Refer here

CI-CD Azure devops for function app deployment

My Function app Name:
my_func_dev_app
Functions I have in my project
func_dev
func_prd
Push func_dev to my_func_dev_app
Push func_prd to my_func_prd_app
But It is pushing both func_dev and func_prd to my_func_de_app
My app folder structure
(folder)myapp_function
(folder)func_dev --__init__.py
-- function.json
(folder)func_prd --__init__.py
-- function.json
task.py
Multi stage Pipeline:
#pipelines1
trigger:
- '*'
stages:
- stage: 'Build'
displayName: 'Build the web application'
jobs:
- job: 'Build'
displayName: 'Build job'
pool:
name: 'onprem_agent'
steps:
- task: CopyFiles#2
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
inputs:
SourceFolder: '$(Build.SourcesDirectory)'
Contents: |
**/*
!.git/**
OverWrite: true
CleanTargetFolder: true
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: ArchiveFiles#2
displayName: "Archive files"
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/myapp_function'
includeRootFolder: false
archiveFile: '$(Build.ArtifactStagingDirectory)/build$(Build.BuildId).zip'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'myapp_function'
- stage: 'DEV_AZURE'
displayName: 'Az DEV Deploy'
dependsOn: Build
condition: |
and
(
succeeded(),
eq(variables['Build.SourceBranchName'], variables['releaseBranchName'])
)
jobs:
- deployment: Deploy
environment: dev
variables:
- group: Release
strategy:
runOnce:
deploy:
steps:
- download: current
artifact: myapp_function
displayName: Downloading artifacts
- task: AzureFunctionApp#1
inputs:
azureSubscription: CI-CD
appType: functionAppLinux
appName: my_func_dev_app
package: '$(Pipeline.Workspace)/myapp_function/*.zip'
deployToSlotOrASE: true
resourceGroupName: my-rg
slotName: PRODUCTION
displayName: 'Deploying dev'
How to fix? Push func_dev to my_func_dev_app and ignore func_prd
How to fix? Push func_dev to my_func_dev_app and ignore func_prd
To solve this issue, you can package your two projects separately into zip.
In your ArchiveFiles task, you need to specify a specific project.
For example:
For func_dev project: $(Build.ArtifactStagingDirectory)/myapp_function/func_dev
- task: ArchiveFiles#2
displayName: "Archive files"
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/myapp_function/func_dev'
includeRootFolder: false
archiveFile: '$(Build.ArtifactStagingDirectory)/build$(Build.BuildId)-func_dev.zip'
Then you can only package the project corresponding to the function app name.
If you want to deploy two projects to the corresponding function app in one pipeline at the same time, you could use the same method to separately package the two projects as zip.

Resources