I am trying to set up an Azure devops pipeline that runs on a virtual machine in Azure. I’m doing the build in azure and the download the artifact to the VM for deployment. However, when I try to run tasks like web.config transform or file copy, I get an error like this:
##[error]The current operating system is not capable of running this task. That typically means the task was written for Windows only. For example, written for Windows Desktop PowerShell.
##[debug]System.InvalidOperationException: The current operating system is not capable of running this task. That typically means the task was written for Windows only. For example, written for Windows Desktop PowerShell.
This quite odd since the VM is running windows.
I have made sure to install the latest version of powershell
2
Answers
Try installing Windows Desktop PowerShell on the virtual machine and see if that resolves the issue.
After you use a self-hosted agent for Windows, Make sure you have referenced windows as a host pool in your YAML pipeline. Also, If you’re using the azure PowerShell task, Make sure you have installed the Powershell module in your VM acting as a self-hosted agent.
I created one windows VM (Windows Server 2019 Datacenter Gen2) in Azure Portal and authorized it to work as a self-hosted agent in Azure DevOps with the PAT token like below:-
Self hosted agent is online in Azure DevOps:-
Now, I ran an Azure-Powershell inline script with this Agent in Azure DevOps :-
Yaml pipeline code:-
The Azure Powershell script ran successfully like below:-
Now, when I ran another SQL Inline script with my pool set to another agent OR ubuntu-image, I got same error code as yours:-
Pipeline Output:-
When I changed the pool to windows, the error was resolved and the task ran successfully like below:-
Pipeline Output:-
Make sure you’re selecting the correct pool and the Powershell module is installed properly inside that VM which is acting as an Azure DevOps agent.
Reference:-
The current operating system is not capable of running this task. That typically means the task was written for Windows only. For example, written for Windows Desktop PowerShell. – AzureFileCopy@4 | What I Broke – Programming and Web Development