0

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

1
  • how should anyone know if you don't provide the code of your pipeline? Commented Feb 2, 2023 at 14:54

2 Answers 2

2

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

enter image description here

enter image description here

Self hosted agent is online in Azure DevOps:-

Note- It is a part of Default Pool in my Azure DevOps org

enter image description here

Now, I ran an Azure-Powershell inline script with this Agent in Azure DevOps :-

Yaml pipeline code:-

# Starter pipeline

# Start with a minimal pipeline that you can customize to build and deploy your code.

# Add steps that build, run tests, deploy, and more:

# https://aka.ms/yaml

  

trigger:

- main

  

pool:

name: Default

  

steps:

- script: echo Hello, world!

displayName: 'Run a one-line script'

  

- script: |

echo Add other tasks to build, test, and deploy your project.

echo See https://aka.ms/yaml

displayName: 'Run a multi-line script'

  

- task: AzurePowerShell@5

inputs:

azureSubscription: 'SID subscription(xxxxxx365-f598-44d6-xxxx-e2b6e97cb2a7)'

ScriptType: 'InlineScript'

Inline: 'Get-AzResource | Format-Table'

azurePowerShellVersion: 'LatestVersion'

Note:- I have added pool as Default where my agent pool is connected
in Azure DevOps, Make sure you use the correct pool here in your YAML
code:-

pool:

name: Default

The Azure Powershell script ran successfully like below:-

enter image description here

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

trigger:

- main

  

pool:

vmImage: ubuntu-latest

Pipeline Output:-

enter image description here

When I changed the pool to windows, the error was resolved and the task ran successfully like below:-

trigger:

- main

  

pool:

vmImage: windows-latest

Pipeline Output:-

enter image description here

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! It was the pool setting! I had for some mysterious reason commented it out in this particular pipeline.
0

Try installing Windows Desktop PowerShell on the virtual machine and see if that resolves the issue.

1 Comment

I did. no change :-(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.