Azure DevOps pipelines self-hosted agent using Azure Function app

huangapple go评论96阅读模式
英文:

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

同样,对于用于函数应用资源的专用应用服务计划,也适用相同的情况。我创建了一个专用应用服务函数应用,步骤如下:

我创建了一个目录来下载代理并从下面的部分运行命令:

Azure DevOps pipelines self-hosted agent using Azure Function app

现在,我访问了我的函数应用 > 左侧窗格 > 开发工具 > 高级工具 > 进入 > 调试控制台 > PowerShell > PowerShell终端将打开,输入以下命令:

我的具有专用计划的函数应用:

Azure DevOps pipelines self-hosted agent using Azure Function app

Azure DevOps pipelines self-hosted agent using Azure Function app

mkdir agent

输出:

Azure DevOps pipelines self-hosted agent using Azure Function app

创建代理目录后,我运行了以下命令,在我的应用服务计划中下载代理,但它失败了,不支持,因为它引发了引发Azure支持的警告。参考以下链接:

命令 reference1reference2

[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

Azure DevOps pipelines self-hosted agent using Azure Function app

我在本地计算机中下载了代理,并直接将其拖到kudu控制台中,并尝试运行安装代理的命令,但又失败了,因为应用服务控制台需要Console.Read。参考以下:

Azure DevOps pipelines self-hosted agent using Azure Function app

代理文件成功传输到应用服务计划:

Azure DevOps pipelines self-hosted agent using Azure Function app

Azure DevOps pipelines self-hosted agent using Azure Function app

代理文件成功传输后,我运行了以下命令,但它失败了:

命令:

./config.cmd

Azure DevOps pipelines self-hosted agent using Azure Function app

错误:

Azure DevOps pipelines self-hosted agent using Azure Function app

无法在应用程序没有控制台或控制台输入已被重定向时读取键。请尝试使用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:-

Azure DevOps pipelines self-hosted agent using Azure Function app

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:-

Azure DevOps pipelines self-hosted agent using Azure Function app

Azure DevOps pipelines self-hosted agent using Azure Function app

mkdir agent

Output:-

Azure DevOps pipelines self-hosted agent using Azure Function app

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

Azure DevOps pipelines self-hosted agent using Azure Function app

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:-

Azure DevOps pipelines self-hosted agent using Azure Function app

Agent file got transferred to App service plan:-

Azure DevOps pipelines self-hosted agent using Azure Function app

Azure DevOps pipelines self-hosted agent using Azure Function app

Agent File got transferred successfully, Now I ran the below commands and it failed:-

Command:-

./config.cmd

Azure DevOps pipelines self-hosted agent using Azure Function app

Error:-

Azure DevOps pipelines self-hosted agent using Azure Function app

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.

huangapple
  • 本文由 发表于 2023年5月22日 21:29:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76306713.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定