Python Azure Function with CiCd Pipeline : ModuleNotFound Error - azure

Hello,
I got an error while deploying azure python function using cicd pipeline. The error is ModuleNotFoundError: No module named 'azure.servicebus'. But the case is, service-bus module already installing while building the package on cicd pipeline.
When direct deploying using vscode or azure cli, the Function app works fine without any error.
working environment and function app python version - 3.7
azure function app version - 3.x
cicd pipeline agent specification - ubuntu-latest
Error -
This error occurs when a function is executed. The function app was deployed using the CiCd pipeline and all dependencies are include in requirements.txt as shown below.
requirements.txt
Here is the pipeline build bash script
Could anyone please help?

I am able to reproduce your issue:
And I can fix this issue:
I know what you are doing. Create virtual environment, active virtual environment, install python packages to the virtual environment...
And you mentioned VS Code/CLI deploy is no problem.
Yes, as you observe, everything should be installed successfully to the virtual environment.
So Why?
The reason is both of VS Code Deploy and CLI deploy doesn't have any relationship with virtual environment, these deployment method only care the requirements.txt file, they don't check others.
And, those operations you done is only work on current agent machine, azure function app you deploy to is another situation. It is a new machine, a new environment.
So you just need to simply design the pipeline like this:
trigger:
- none
pool:
VMAS
steps:
- task: AzurePowerShell#5
inputs:
azureSubscription: 'testbowman_in_AAD'
ScriptType: 'InlineScript'
Inline: 'func azure functionapp publish <Your FunctionApp Name> --build remote'
azurePowerShellVersion: 'LatestVersion'
Working principle of VS Code and CLI
https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=asgi%2Capplication-level#remote-build
By default, Azure Functions Core Tools requests a remote build when
you use the following func azure functionapp publish command to
publish your Python project to Azure. Replace <APP_NAME> with the name
of your function app in Azure.
The Azure Functions extension for Visual Studio Code also requests a
remote build by default.

Related

Bitbucket azure-static-web-apps-deploy is stucking on Publishing to directory /bin/staticsites/ss-oryx/app... step

We have Blazor client side application that we want to deploy as Azure Static Web App.
Unfortunately Static Web App officially support Git Hub Actions and Azure DevOps as deploy options but we are using Bitbucket pipelines currently and switching to GitHub or Azure DevOps is not an option at the moment.
That is why I'm trying to deploy my blazor app to azure using Bitbucket Azure Pipes/azure-static-web-apps-deploy but for some reason it stuck on "Publishing to directory /bin/staticsites/ss-oryx/app..." step and than pipeline fails with timeout error.
Although locally "dotnet publish -c Release" executes for seconds I tried to extend the timeout to one hour with BUILD_TIMEOUT_IN_MINUTES parameter but after one hour timeout again.
Here is my bitbucket-pipelines.yml:
pipelines:
branches:
master:
- step:
name: Deploy to production
deployment: production
script:
- pipe: microsoft/azure-static-web-apps-deploy:main
variables:
APP_LOCATION: '$BITBUCKET_CLONE_DIR/App'
API_TOKEN: $deployment_token
OUTPUT_LOCATION: '$BITBUCKET_CLONE_DIR/wwwroot'
I will be thankful to any hints and suggestions how to solve that...

Node Express Webpack API Release to Azure Dev Ops

I'm trying to release my project using Nodejs Express on Azure Dev Ops and Deploy on Release, but when I try to open the link. I'm getting a "The page cannot be displayed because an internal server error has occurred." error.
YAML:
pool:
name: Azure Pipelines
steps:
task: NodeTool#0
displayName: 'Use Node 14.x'
inputs:
versionSpec: 14.x
task: Npm#1
displayName: 'npm install'
inputs:
verbose: false
task: Npm#1
displayName: 'npm custom'
inputs:
command: custom
verbose: false
customCommand: 'run build'
task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(System.DefaultWorkingDirectory)'
Package Script
Webpack.config
and on Azure Pipeline
the default setting of npm install and build
and on Azure Release
All are working fine, on the build and release.
Blank Page
I'm starting to guess the problem was from the azure portal, or on the way it was setup. Because I didn't create the portal. I'm only the Contributor.
Please help clarify this.
I try to build all files on SCM \wwwroot
Make sure the index.js file is deployed to your azure app service
As you have some issues with your existing application Create the new application using this MS-DOC
Sign into Azure Pipelines. Your browser will go to to display your Azure DevOps dashboard.
Create New pipeline under the pipeline's menu of your project
Select GitHub as the source code location.
If the code is placed in GitHub, then login with Git Creds
When the list of repositories appears, select your sample Node.js repository.
Azure Pipelines analyzes the code in your repository and automatically gives a Node.js template for your pipeline. Select this template.
Azure Pipelines will automatically generates a YAML file in your pipeline. Click on Save and Run > Commit Directly to Master Branch and then choose Save ad Run again.
A new run begins. Wait for the run to complete.
The link is used to create a pipeline is azure devops Deploying a Node JS App to Azure App Service using Azure Dev-ops (Part 1)
The link will be used to deploy the Nodejs app to Azure portal using azure pipelines Deploying a Node JS App to Azure App Service using Azure Dev-ops (Part 2)
This error is a common description of the IIS server error 500. It will be difficult to find the root cause of the question with just a general description.
For more details, please Reference the SO-Thread

Is there a handy way to use Bicep modules in an Azure DevOps pipeline?

I am setting up my Azure DevOps pipeline (an Azure CLI task) with the intention of deploying a resource group and several resources within it. So far I have been able to deploy and validate from my local pc with no issues however when I configure my pipeline in DevOps I get the following error message:
C:\devops_work\11\s\main_v2.bicep(55,29) : Error BCP091: An error occurred reading file. Could not find a part of the path 'C:\devops_work\11\isv-bicep\storage_account.bicep'.
For context, 'main_v2.bicep' is my "main file" where the modules are called, in this case, "storage_account.bicep"
The same error occurs for all other modules. A couple of details regarding my pipeline:
I am using my own agent pool
My code sits in an Azure Repository
I have tried checking 'Checkout submodules' (Any nested submodules within)
The files all sit at the root level of the repository
My pipeline is not a YAML pipeline
Any help or insight into this is duly appreciated
You need to specify the working directory and ensure that your repository is being cloned.
steps:
- checkout: self
- powershell: |
az deployment group create `
-f "your-bicep-file.bicep" `
-g "your-resource-group-name"
workingDirectory: $(Build.SourcesDirectory)
If the pipeline is not in the same repository as your bicep files, on the checkout change self by the name of the repository alias, and complement the working directory with the path (By default it is cloned into $(Build.SourcesDirectory), but if you check out more than one repo it adds an extra directory).
steps:
- checkout: <your repo alias>
- powershell: |
az deployment group create `
-f "your-bicep-file.bicep" `
-g "your-resource-group-name"
workingDirectory: $(Build.SourcesDirectory)/<your repo alias>

Simple Appium test in Azure Pipeline - how do I fix the failing build step (vstest)?

Given:
Appium Windows Application Driver
Visual Studio 2019 solution
WPF Project .Net 4.7.2
Unit Test MSTest .Net 4.7.2
Azure DevOps Pipelines
I have a minimalist solution with a WPF project that just has a label "Hello World." In the unit test project I'm using Appium to test the existence of Hello World. Very simple and runs successfully locally.
However, when I put in build in Azure DevOps my one and only test fails and I can't figure out why.
Here's the Microsoft documentation that says Microsoft hosted agents are preconfigured to run Appium Tests.
Here's a link to my Azure DevOps
Below error is abstracted from the vstest task log. It seems the WinAppDriver didnot startup correctly in the hosted agent.
OpenQA.Selenium.WebDriverException: OpenQA.Selenium.WebDriverException: Unexpected error. System.Net.WebException: Unable to connect to the remote server --->
...
at UnitTestProject1.WpfAppSession.Setup() in d:\a\1\s\RsSolution6\UnitTestProject1\WpfAppSession.cs:line 31
at UnitTestProject1.UnitTest1.ClassInitialize(TestContext context) in d:\a\1\s\RsSolution6\UnitTestProject1\UnitTest1.cs:line 20
There's now a dedicated WinAppDriver Pipelines Task available on the Azure Marketplace to help you easily enable and configure WinAppDriver from inside your DevOps Pipeline. See
WinAppDriver in CI with Azure Pipelines.
Install WinAppDriver task to your organization, and add it in your pipeline to start and stop winappdriver.
- task: Windows Application Driver#0
inputs:
OperationType: Start
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: Windows Application Driver#0
inputs:
OperationType: Stop

Azure pipeline BatchScript task is not running the script on the machine its deploying to

I have an azure deployment pipeline that copy files to an azure VM hosted on my account using this task:
- task: AzureFileCopy#3
inputs:
SourcePath: '$(Build.ArtifactStagingDirectory)'
azureSubscription: 'qa-serverside-snapshots'
Destination: 'AzureVMs'
storage: 'serversidesnapshotsdiag'
enableCopyPrerequisites: true
resourceGroup: 'SERVERSIDE-SNAPSHOTS'
vmsAdminUserName: $(username)
vmsAdminPassword: $(password)
TargetPath: 'C:\Git\serverside-snapshots'
The issue is I run into errors pertaining to not being able to write to a file because it is in use by the service running on the machine. So what I want to do is run a bat script that stops the service on the azure VM. Here was my attempt:
- task: BatchScript#1
inputs:
filename: '$(Build.SourcesDirectory)\stopPM2.bat'
workingFolder: 'C:\Git\serverside-snapshots'
"stopPM2.bat" literally just contains pm2 stop myservice. The issue is, when the bat file gets ran, I get this error:
C:\Git\serverside-snapshots>pm2 stop myservice
'pm2' is not recognized as an internal or external command,
operable program or batch file.
##[error]Process completed with exit code 1.
I definitely have PM2 installed on the server I'm deploying to. It looks like the bat file isn't actually getting run on the VM I'm trying to deploy to, but its running on the temporary VM that the pipeline in running stuff on. So my question is, how do I get a bat script to run on the VM I'm deploying to so I can stop the service before copying files?
BatchScript runs on the build agent.
You need to use PowerShell on Target Machine or SSH on Target Machine to invoke something on a remote machine.

Resources