How to invoke azure function manually from /wwwroot - azure-devops

I'm using AzureDevops to deploy Azure Function with time trigger.
This is deployment yaml section:
- task: AzureFunctionApp#1
displayName: 'Deploy Function App initImporter'
inputs:
azureSubscription: AzureAutomationSP # Azure service connection
appType: functionApp
appName: $(appName)
package: $(System.ArtifactsDirectory)/**/*.zip
deploymentMethod: runFromPackage
Everything is ok, but App deploys directly to /wwwroot of Function App.
I need to manually trigger it according this guide - https://learn.microsoft.com/en-us/azure/azure-functions/functions-manually-run-non-http
But, the question is that I don't have a subfolder in /wwwroot/{func name}, so I don't know how to build URL.
When i deploy func manually, everything works. But i'm stuck with invoking app from /wwwroot.
az functionapp function show --resource-group MyResourceGroup --name MyFunctionAppName --function-name MyFunctionName also doesn't work, because i don't have "function-name"
P.S. Found quite similar unanswered question - How to change azure web app default deployment directory from WWWROOT to WWWROOT/webapps?
There could be two options, deploy to subfolder or invoke directly from site/wwwroot

Related

Azure devops resource not found stopping webapp

I have a azure devops pipeline with three stages:
- Release_infrastructure_Core
- Release_infrastrcuture_App
- Release_webapps
In the first stage ("Release_infrastructure_Core") among other task a WebApp called "Core-wst-api" with a webjob is created.
In the "Release_webapps" stage I need stop the the webapp "Core-wst-api" and execute the webjob through the exposed webhook,
Trying to stop the webapp I'm getting this error.
##[error]Error: Resource 'Core-wst-api' doesn't exist. Resource should exist before deployment.
Checking in Azure portal the weapp had been properly created.
This is the code to stop the webapp
task: AzureAppServiceManage#0
displayName: 'Stop API'
inputs:
azureSubscription: ${{ parameters.serviceConnectionName }}
Action: 'Stop Azure App Service'
WebAppName: 'Core-wst-api'
I'm trying executing only the stop task and it doesn't work.
If I put in the same stage the webapp publish task and STOP Api task its works ok

Getting error "Could not find the modules: 'Az.Accounts'" When trying to run Azure DevOps Multi-Stage Yaml using Self hosted Agent (Windows 2019)

I am Getting error
##[error]Could not find the modules: 'Az.Accounts' with Version: '5.1.1'. If the module was recently installed, retry after restarting the Azure Pipelines task agent
When trying to run Azure DevOps pipeline using Multi-Stage Yaml using Self hosted Agent (Windows 2019)
The Yaml:
- task: AzurePowerShell#5
displayName: 'Disconnect DEV Function App'
inputs:
azureSubscription: '$(DEVAzureSvcCon)'
ScriptType: 'InlineScript'
Inline: 'az webapp deployment source delete --resource-group $(DEVResourceGroup) --name $(DEVFunctionAppName)'
FailOnStandardError: true
preferredAzurePowerShellVersion: '5.1.1'
I have tried multiple versions for powershell including "latest" but no dice. I have also RDP'd into the agent servers and have installed az cli on powershell using admin mode and Install-Module -Name Az -Scope AllUsers. What am I doing wrong?
Though you are using Powershell in your tasks, what you are actually running in the Inline script is az cli. Since you are using a self hosted agent, you’d have to install az cli in your machine and then try.
https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?tabs=azure-cli

Azure release pipeline (YAML) IIS web deploy fails on locked files generating ERROR_FILE_IN_USE

Actual
Release pipeline fails when deploying
Expected
Deploy does not fail
Root cause
File 'Microsoft.Data.SqlClient.SNI.x86.dll' is locked locked by an external process, even when 'Take App Offline Flag' setting is on
Workaround
Recycle application pool manually and rerun failed deploy.
Trying to automate the recycle also failed when applying the 'Action IIS Application Pool' setting with 'recycleAppPool'.
Information
Error message
Error Code: ERROR_FILE_IN_USE More Information: Web Deploy cannot modify the file 'Microsoft.Data.SqlClient.SNI.x86.dll' on the destination because it is locked by an external process.
In order to allow the publish operation to succeed, you may need to either restart your application to release the lock, or use the AppOffline rule handler for .Net applications on your next publish attempt.
Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_FILE_IN_USE. Error: The process cannot access the file because it is being used by another process.
For those who aren't using the Azure App Service yet.
- task: IISWebAppManagementOnMachineGroup#0
displayName: Stop AppPool
inputs:
IISDeploymentType: 'IISApplicationPool'
ActionIISApplicationPool: 'StopAppPool'
StartStopRecycleAppPoolName: '$(AppPoolName)'
[deploy application here]
- task: IISWebAppManagementOnMachineGroup#0
displayName: Start AppPool
inputs:
IISDeploymentType: 'IISApplicationPool'
ActionIISApplicationPool: 'StartAppPool'
StartStopRecycleAppPoolName: '$(AppPoolName)'
More information:
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/iis-web-app-management-on-machine-group?view=azure-devops
Azure release pipeline (YAML) IIS web deploy fails on locked files generating ERROR_FILE_IN_USE
You could add two task, a stop app service task before deployment and a start app service task after the deployment:
- task: AzureAppServiceManage#0
displayName: 'Stop Azure App Service: tomsun'
inputs:
azureSubscription: 'xxxx'
Action: 'Stop Azure App Service'
WebAppName: xxxx
- task: AzureAppServiceManage#0
displayName: 'Stop Azure App Service: tomsun'
inputs:
azureSubscription: 'xxxx'
Action: 'Restart Azure App Service'
WebAppName: xxxx
And you could also try to configure the appOffline rule in the publishing profile (.pubxml). Add the EnableMSDeployAppOffline element to the PropertyGroup like this:
<PropertyGroup>
<EnableMSDeployAppOffline>true</EnableMSDeployAppOffline>
</PropertyGroup>
Please check this document ERROR_FILE_IN_USE and this thread for some more details.

How to create CI/CD pipeline for QnAMaker ChatBot Virtual Assistant Template in Azure DevOps

I am using Bot Framework Virtual Assistant template to Create and configure Bot in Azure,
For this process i have ARM template is in place for creating resources,
Deploy PS script is used to create knowledgebase and (Deploy.ps1) once qnamaker resources are created.
In current implementation, If i execute script from local Powershell tool everything works fine:
Creating Resources
Creating Knowledgebase
KnowledgeBase configuration
I am stuck at configuring this set up in Azure DevOps, How do i configure ARM deployment and PowerShell script execution in CI/CD pipeline.
So that once resources are created through ARM deployment, Knowledgebase creation should automatically trigger ?
Any help is appreciated
First you need to put the ARM template in a source repository(Github or Azure Repos). See document Create a new Git repo in your project
Then Create the pipeline(Yaml or Classic). See YAML example here. For Classic UI pipeline check out this example.
Before you can deploy to your Azure subscription. You need to create an azure Resource Manager service connection to connect your Azure subscription to Azure devops. See this thread for an example
In your pipeline use ARM template deployment task to deploy the ARM template. And use Azure powershell task to execute the Deploy PS script. See below example
trigger:
- master
pool:
vmImage: windows-latest
steps:
- task: AzureResourceManagerTemplateDeployment#3
displayName: 'ARM Template deployment: Subscription scope'
inputs:
azureResourceManagerConnection: 'my-azure-sub'
resourceGroupName: 'azrue resource group'
location: 'West Europe'
csmFile: **/template.json
csmParametersFile: **/parameter.json
deploymentMode: Incremental
- task: AzurePowerShell#5
displayName: 'Azure PowerShell script: FilePath'
inputs:
azureSubscription: 'my-azure-sub'
ScriptPath: **/Deploy.ps1
azurePowerShellVersion: LatestVersion
See this tutorial for more information.

How to deploy to azure web app containers using a docker hub registry

As part of my azure pipelibe I build a docker image and push it to my docker hub registry. Then I would need to deploy it to an Azure Web App for Containers and for that I have been trying to add the code below:
- stage: Deploy
displayName: Deploy to App Service
jobs:
- job: Deploy
displayName: Deploy
pool:
vmImage: 'ubuntu-latest'
steps:
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: $(azureSubscription)
appType: 'webAppContainer'
WebAppName: $(webappName)
DockerNamespace: 'https://index.docker.io/v1'
DockerRepository: 'my_id/name_of_my_image'
DockerImageTag: $(tag)
But I keep receiving the below error on the portal logs in the container settings
ERROR - DockerApiException: Docker API responded with status code=BadRequest, response={"message":"invalid reference format"}
The repo is private but I have tried to change it to public and that didn't work either, and I have a connection service to docker hub and the app settings, not sure if were needed, have the correct values
I have found much more documentation when using azure registry but the few I found for docker hub hasn't helped me so would appreciate it if someone knows what to do here
Thanks
Just trial and error, it seems to work with the wokspace being 'index.docker.io'. I might understand not needig 'https://', as there is a reference to "high level domain" (although in some of the several places I was checking read something about not needing it in docker hub but need it elsewhere)
Not needind the v1 segment surprises me, though
But it works