1

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.

crystyxn
  • 1,411
  • 4
  • 27
  • 59
  • 2
    I do not think it is directly possible to convert Azure Function app into Self hosted agent as Azure functions is a serverless compute which scales up and down based on the triggers requirement. And self hosted agent is a dedicated VM running Pipelines. One alternative is to Dockerized your Function app and use Self hosted agent running in Docker as given here -https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/docker?view=azure-devops#use-azure-functions-custom-container-feature-to-create-a-self-hosted-agent – SiddheshDesai May 22 '23 at 14:14
  • 1
    What if the hosting for the function app is an app service plan? that one is a dedicated environment – crystyxn May 22 '23 at 14:23
  • 1
    Adding an agent requires you to run this commands and download agent - https://i.imgur.com/IRgj1sv.png you can go to your Function app > Advanced Tools > Kudu > Debug > Powershell and try downloading the Agent via Invoke- (Invoke-webrequest -URI "http://www.kernel.org").Content reference- https://stackoverflow.com/questions/1973880/download-url-content-using-powershell – SiddheshDesai May 22 '23 at 14:50
  • If the above method does not work, Then unfortunately its not possible – SiddheshDesai May 22 '23 at 14:51

1 Answers1

1

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

enter image description here

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

enter image description here

enter image description here

mkdir agent

Output:-

enter image description here

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

enter image description here

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

enter image description here

Agent file got transferred to App service plan:-

enter image description here

enter image description here

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

Command:-

./config.cmd

enter image description here

Error:-

enter image description here

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.

SiddheshDesai
  • 3,668
  • 1
  • 2
  • 11