Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: How to authenticate using accesstoken to call devops API from custom task #19450

Closed
2 of 4 tasks
tbolon opened this issue Jan 17, 2024 · 3 comments
Closed
2 of 4 tasks

Comments

@tbolon
Copy link

tbolon commented Jan 17, 2024

Task name

No response

Task version

No response

Environment type (Please select at least one enviroment where you face this issue)

  • Self-Hosted
  • Microsoft Hosted
  • VMSS Pool
  • Container

Azure DevOps Server type

Azure DevOps Server (Please specify exact version in the textbox below)

Azure DevOps Server Version (if applicable)

2022.1

Operation system

Windows Server 2022

Question

Hi,

I want to create a custom powershell task to promote packages uploaded to Azure Artifacts automatically during the build pipeline.

I have successfully created a custom task, but I can't find a way to authenticate my request.

I build the url using the environment variables, which works:

$url = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)_apis/packaging/feeds/$feedName/nuget/packages/" + $pkgName + "/versions/" + $pkgVersion + "?api-version=7.0"

I wanted to authenticate using an Authentication HTTP header build manually using $env:SYSTEM_ACCESSTOKEN and using Invoke-RestMethod but it seems the access token is not available in the scope of the custom task.

How am I supposed to call the Azure DevOps server api from inside a powershell custom task?

I did not find an ewisting task doing the same using powershell.

There seems to exists a Vsts .NET Library wrapper, but I am not sure I can easily PATCH the package version to publish it to a field, and I can not find how I am supposed to import this library.

@tbolon
Copy link
Author

tbolon commented Jan 18, 2024

I have found this issue microsoft/azure-pipelines-task-lib#579 in azure-pipeline-task-lib but for the typescript language. Feel free to move this issue to the other repo if more appropriate.

@vmapetr vmapetr self-assigned this Jan 22, 2024
@vmapetr
Copy link
Contributor

vmapetr commented Apr 2, 2024

Hi @tbolon, thank you for your question.
Since this issue is related to the task lib repo and this repo is mostly for pipeline tasks - could you please open the ticket on the https://github.com/microsoft/azure-pipelines-task-lib?

@tbolon
Copy link
Author

tbolon commented Apr 2, 2024

@tbolon tbolon closed this as completed Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants