3

I am looking to run some CURL commands (GET mainly) in an Azure Pipeline Task to list/download some artifacts from a few sources. Would appreciate some help with any examples of how I can achieve this through a Pipeline Task using CURL, Powershell, Windows Command or any other appropriate method.

Thanks

hitman126
  • 699
  • 1
  • 12
  • 43

2 Answers2

7

The easiest way to do this is to use the Command Line task. For a YAML pipeline, this would look like

- task: CmdLine@2
  displayName: Curl Example
  inputs:
    script: 'curl google.com'

For a "Classic UI" pipeline, it would look like

enter image description here

Note that for either of these options you must be using a Linux build agent. If you are using a Windows build agent, you should use Invoke-WebRequest.

pirateofebay
  • 930
  • 1
  • 10
  • 25
  • @VitoLiu-MSFT, thanks for the response which is excellent. However, having set up the Powershell Task in Azure Pipelines, I'm still having an issue when attempting to download a Maven package (which was not originally created in Azure DevOps but has been imported into Azure Artifacts from an external project) from my feed. It appears to fail on the authentication method used in my Invoke-WebRequest command. Any idea how to resolve this? – hitman126 Jan 21 '21 at 10:00
  • Is `curl` command even available in a pipeline? – djangofan Aug 17 '21 at 17:00
3

curl in PowerShell uses Invoke-WebRequest. From PowerShell 3.03.0 and above, we could use Invoke-WebRequest, which is equivalent to curl. You could refer to this doc for more details

Sample script in the power shell

 Invoke-WebRequest -URI https://www.educative.io/

In addition, in the Azure DevOps Artifacts, the URL contain special characters, we need use "" contain it. Such as

https://dev.azure.com/{Org name}/{project name}/_packaging?_a=feed+"&"+feed={feed name}
Vito Liu
  • 7,525
  • 1
  • 8
  • 17