英文:
Azure DevOps pipelines self-hosted agent using Azure Function app
问题
我正在尝试弄清楚是否可以将Azure Function应用程序转化为自托管代理,用于运行流水线。
根据这篇文章,您可以将任何带有Linux的计算机变成代理。但是,我想避免使用专用虚拟机。是否可能让函数应用程序充当自托管代理?我找不到关于此的任何信息。
英文:
I am trying to figure out if it is possible to make an Azure Function app into a self-hosted agent for pipeline running purposes.
https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/linux-agent?view=azure-devops
According to this article, you can turn any computer with Linux into one. However, I would like to avoid a dedicated Virtual Machine. Is it possible to have a function app act as a self-hosted agent? I could not find any information on this.
答案1
得分: 1
将评论发布为答案以帮助社区。
无法直接将Azure函数应用程序转换为自托管代理,因为Azure函数是一种无服务器资源,根据触发器的需求进行伸缩。另一种方法是将您的函数应用程序制作成Docker容器,然后在Docker函数中运行自托管代理。参考链接:在Docker中运行自托管代理 - Azure Pipelines | Microsoft Learn
同样,对于用于函数应用资源的专用应用服务计划,也适用相同的情况。我创建了一个专用应用服务函数应用,步骤如下:
我创建了一个目录来下载代理并从下面的部分运行命令:
现在,我访问了我的函数应用 > 左侧窗格 > 开发工具 > 高级工具 > 进入 > 调试控制台 > PowerShell > PowerShell终端将打开,输入以下命令:
我的具有专用计划的函数应用:
mkdir agent
输出:
创建代理目录后,我运行了以下命令,在我的应用服务计划中下载代理,但它失败了,不支持,因为它引发了引发Azure支持的警告。参考以下链接:
命令 reference1 和 reference2
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri 'https://vstsagentpackage.azureedge.net/agent/3.220.2/vsts-agent-win-x64-3.220.2.zip' -UseBasicParsing
输出:错误
Invoke-WebRequest : Win32 internal error "The handle is invalid" 0x6 occurred
PS C:\home> while reading the console output buffer. Contact Microsoft Customer Support
Services.
At line:1 char:1
+ Invoke-WebRequest -Uri 'https://vstsagentpackage.azureedge.net/agent/ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ReadError: (:) [Invoke-WebRequest], HostExceptio
n
+ FullyQualifiedErrorId : ReadConsoleOutput,Microsoft.PowerShell.Commands.
InvokeWebRequestCommand
我在本地计算机中下载了代理,并直接将其拖到kudu控制台中,并尝试运行安装代理的命令,但又失败了,因为应用服务控制台需要Console.Read。参考以下:
代理文件成功传输到应用服务计划:
代理文件成功传输后,我运行了以下命令,但它失败了:
命令:
./config.cmd
错误:
无法在应用程序没有控制台或控制台输入已被重定向时读取键。请尝试使用Console.Read更改默认安装Azure自托管代理的代码,但这种情况不可行。除了将函数制作为Docker容器之外,还有另一种选择,那就是将一个独立的Windows或Linux虚拟机托管为自托管代理,并在其中本地创建函数应用,并通过Azure Devops管道在其中运行。
英文:
Posting the comments as an answer to help community.
Its not possible to convert the Azure Function app into Self hosted agent directly, As Azure Function is a serverless resource which scales up and down depending on your trigger's requirement. An alternative is to Dockerize your Function app and run a Self hosted agent in a Docker Function, Reference - Run a self-hosted agent in Docker - Azure Pipelines | Microsoft Learn
Same goes for your Dedicated App service plan used for your Function app resource, I Deployed one Dedicated App Service Function app like below:-
I created one directory to download the agent and run the commands from the section below:-
Now, I visited my Function app > Left pane > Development Tools > Advance Tools > Go > Debug Console > Powershell > powershell terminal will open type below command:-
My Function app with dedicated plan:-
mkdir agent
Output:-
After creating agent directory, I ran below command to download the agent in my App service plan but it failed and its not supported as it raised a warning to raise Azure support, Refer below:-
Command reference1 and reference2
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri 'https://vstsagentpackage.azureedge.net/agent/3.220.2/vsts-agent-win-x64-3.220.2.zip' -UseBasicParsing
Output:- Error
Invoke-WebRequest : Win32 internal error "The handle is invalid" 0x6 occurred
PS C:\home> while reading the console output buffer. Contact Microsoft Customer Support
Services.
At line:1 char:1
+ Invoke-WebRequest -Uri 'https://vstsagentpackage.azureedge.net/agent/ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ReadError: (:) [Invoke-WebRequest], HostExceptio
n
+ FullyQualifiedErrorId : ReadConsoleOutput,Microsoft.PowerShell.Commands.
InvokeWebRequestCommand
I downloaded the Agent in my local machine and directly dragged it in the kudu console and tried running command to install the agent but it failed again as App service console requires Console.Read instead refer below:-
Agent file got transferred to App service plan:-
Agent File got transferred successfully, Now I ran the below commands and it failed:-
Command:-
./config.cmd
Error:-
Cannot read keys when either application does not have a console or when console input has been redirected. Try Console.Read.
As we cannot change the default code of installing the Azure Self hosted agent and write Console.Read, This scenario is not possible. Another alternative apart from Dockerizing Function is to host an individual Windows or Linux VM as a self hosted agent and create Function app locally inside it and run it via Azure Devops pipeline.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论