Azure CLI commands not working inside azure functi

2020-05-03 01:41发布

问题:

I have powershell scripts which is running locally.But those scripts not running insite function apps > powershell (windows) machine.

az login --service-principal -u $ServicePrincipalId -p $ServicePrincipalPass --tenant $ServicePrincipalTenant

Getting below when i run the script

ERROR: The term 'az' is not recognized as the name of a cmdlet, function, script file, or operable program.

since i dont have az cli installed in the windows machine, i have added below line to install az command in my script.

Install-Module -Name Az -AllowClobber  -Scope CurrentUser

Getting access issue while installing the az.

2019-06-11T12:42:59.698 [Warning] WARNING: InternalWebProxy: Could not find a part of the path 'D:\Program Files (x86)\SiteExtensions\Functions\2.0.12507\32bit\workers\powershell\runtimes\win-x86\lib\netcoreapp2.1\ref'.
2019-06-11T12:42:59.843 [Warning] WARNING: Win32Helpers: Could not find a part of the path 'D:\Program Files (x86)\SiteExtensions\Functions\2.0.12507\32bit\workers\powershell\runtimes\win-x86\lib\netcoreapp2.1\ref'.
2019-06-11T12:43:05.023 [Warning] WARNING: User declined to install module (Az).

even -Force is not working. need to know what is causing the issue.

Note :- The script is perfectly running in local windows machine. the issue is when try to run on portal > functionapp> timertrigger

Attaching azure function app creating with windows machine

Getting error after adding cli folder into kudu

> 2019-06-13T12:29:40.510 [Error] ERROR:   File
> "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands\__init__.py", line 523, in execute Microsoft.Azure.WebJobs.Script.Rpc.RpcException :
> Result: ERROR:   File
> "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands\__init__.py", line 523, in execute Exception:   File
> "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-68v0_w99\azure-cli-core\azure\cli\core\commands\__init__.py", line 523, in execute

kudu console

回答1:

As the error shows that you do not install the Azure CLI in the environment. To install the Azure CLI, a possible way is to copy the whole CLI directory that you installed in the local machine to your function KUDU path /home.

In the test, the copy path in the function KUDU is D:/home/CLI2/.

Test code:

D:/home/CLI2/wbin/az.cmd login --service-principal -u 'xxxxxx' -p 'xxxxxx' --tenant 'xxxxxx' | Write-Host

The screenshot of the output: