How to authenticate azure devops pipeline , so that pipeline can restore yarn packages successfully - azure-devops

My application uses an yarn package which is installed in local after authentication.Registry url is specified in .npmrc file. Now my build pipeline fails, and says "Package restore failed" (Request failed "401 Unauthorized""). How to authenticate the azure devops build pipeline?
I tried adding a task in my YML file as below , specified the npmrc path in it,so that it silently authenticate from the pipeline process, but this doesn't work
task: npmAuthenticate#0
inputs:
workingFile: "Portal/.npmrc"
customEndpoint: msasg.pkgs.visualstudio.com, 1DS-SDK
displayName: "Authenticate NPM"
Is there a different way to achieve this?

You can try to use Yarn Task from the Marketplace as it is more Azure DevOps aware and can handle this credentials bit for you.
In addition, the yarn package you use is installed locally, do you use a self-hosted agent to run the pipeline ?

Related

Azure pipelines - How to manage versions of the tasks?

I would like to understand how the tasks work in Azure pipeline, and where can I find the documentation for it.
I have a self-hosted agent where I have installed Terraform, Azure CLI and Azure Powershell.
There are some tasks defined for them, I actually have difficulties to find them in a documentation,for example with terraform, I have to go to azure release and simulate an action of adding task, then convert that in yaml and there I have the task name:
steps:
- task: ms-devlabs.custom-terraform-tasks.custom-terraform-release-task.TerraformTaskV3#3
displayName: 'Terraform : azurerm'
inputs:
command: custom
customCommand: import
environmentServiceNameAzureRM: 'something'
Also, some tasks asks to install some resources in order to use them, will it affect the resources of my self-hosted agent? for example if we have to install the task before using it ,will it affect somehow the version of my self-hosted terraform?
I have azure powershell installed in the self-hosted agent with an old version, but there is a task that in the version parameter has the latest version, but when executing the task it uses my old version.
How versions for tasks work? Can I use the latest version or az cli without installing it in the self-hosted agent but only with the tasks for the deployments only?
- task: AzurePowerShell#5
displayName: 'DevCode'
inputs:
#azureSubscription: 'something'
azureSubscription: 'something'
ScriptPath: 'something'
azurePowerShellVersion: LatestVersion
The same for az cli.
For the commonly used pipeline tasks published by Microsoft (such as Azure CLI task and Azure PowerShell task), you can find the related documents here.
All these tasks are open-source on the GitHub repository "microsoft/azure-pipelines-tasks".
For the Terraform task, you can find it on Marketplace here and this GitHub repository.
Normally, the tasks would not change the tools have installed on your self-hosted agent machine, also not automatically install the required tools. They just call the required tools have installed on the agent machine.
For example, when you run the Azure CLI task on your self-hosted agent, if you have installed the Azure CLI tool on the agent machine, the task will call the tool to run the specified scripts. If the Azure CLI tool has not installed on the machine, normally the task will go to failure since it cannot find the required Azure CLI tool on the machine.
You do not need to manage the versions of the tasks, you just use the tasks in your pipelines and select the available released versions of the tasks (latest versions are recommended). If a new version of a task is released, you can go to edit your pipelines to use the new version.

Error while deploying release pipeline in Azure Devops

I am trying to deploy an existing .Net Core application using Azure Devops by creating Build and release pipelines. The build pipeline worked fine, but I get the below error when running the release pipeline (under Deploy Azure App Service).
Error: No package found with specified pattern: D:\a\r1\a***.zipCheck if the package mentioned in the task is published as an artifact in the build or a previous stage and downloaded in the current job.
What should be done to fix this?
This error is because the build task is not configured. You can try to put the below YAML code at the last to make it work.
- task: PublishBuildArtifacts#1

"az pipelines runs artifact download" fails with error "Artifact was found, but is of type 'Container'"

"az pipelines runs artifact download --run-id 10976432 --artifact-name "Android/Android" --path "c:/foo/" fails with error "Artifact with name 'Android' was found, but is of type 'Container'"
I publish artifacts from our build runs to several different repositories like NPM, Nuget, PyPi, CoCoPods, and this process requires "two factor authentication", so at least for now it will remain a manual post build process for us.
But even though this is a manual process, I want to automate as much of it as I can, e.g. automating the download a dozen or more build run artifacts to a local staging directory that I then use to publish from.
I have found several community post that have done this with CURL and the REST apis, but I want to get this working with the az devops extention.
As far as I can tell from the azure extension this command should work, but it does not!
How can I download build run artifacts (not public feed artifacts), so that I can manually or automatically publish them outside for the normal DevOps pipeline?
Thanks,
Brian.
"Artifact with name 'Android' was found, but is of type 'Container'"
I guess the publish task you are using is Publish Build Artifacts task, right? If yes, as the message shown, we indeed does not support download container type artifacts until now.
As of today, you can just download artifacts of type -'Pipeline Artifact' from az cli.
In order to use az cli to download artifacts successfully , if possible, please go replace the publish task with Publish Pipeline Artifact task:
- task: PublishPipelineArtifact#1
inputs:
targetPath: '$(Pipeline.Workspace)'
artifact: 'AzLogicApp'
publishLocation: 'pipeline'
Now, you will see you can succeed to download the artifact with az cli.

Azure DevOps Build Pipeline - Unable to deploy .NET Core app

I'm trying to create a CI/CT pipeline for my project. All the steps got completed successfully including Publish Build Artifacts but unfortunately I get an error during azure webapp deployment
Build Pipeline
Azure publish Step
Publish Artifact: Drop
Azure App Service Deploy: XXXX Server
I get following error in this step
Error: No package found with specified pattern: D:\a\1\a\Drop\xxx.xx.UI.API.zip
Any idea what I am doing wrong?
Remove the "Drop" from the "Package or folder" path in the Azure App Service Deploy task.
Create a release pipeline and use the Azure App Service Deploy task from there.

Azure Pipelines Hosted Agent Can't Access DevOps project Feed

I have an Azure DevOps project (just one).
I have a Build Pipeline set to run in the "Hosted VS2017" Agent Pool. This Agent Pool appears to be in the [MyProject]\Build Administrators, Contributors, Project Administrators, and Release Administrators roles.
I also have an Artifacts nuget feed in the DevOps project. It has [MyProject]\Project Valid Users set as "Reader" role. It appears that Project Valid Users has all of the Agent Pool's roles mentioned above as members.
I have an azure-pipelines.yml script that adds that adds the artifacts feed as a nuget source right at the beginning:
# Add nuget source
- powershell: Invoke-RestMethod "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile "$env:UserProfile/nuget.exe"
- script: '%UserProfile%\nuget.exe sources Add -Name "devops" -Source "https://pkgs.dev.azure.com/MyProject/_packaging/feed/nuget/v3/index.json"'
The build yml then dot a dotnet build but fails inside NuGet.targets with:
Unable to load the service index for source https://pkgs.dev.azure.com/MyProject/_packaging/feed/nuget/v3/index.json.
Response status code does not indicate success: 401 (Unauthorized).
how can I make this work? My build needs packages from other builds that are on that artifacts feed...
There is a better alternative imo. You can continue using your script to dotnet restore.
Simply add a task just before that with NuGetAuthenticate#0
steps:
- task: NuGetAuthenticate#0
- script: dotnet restore --no-cache --force
this task will authenticate the pipeline with the nuget feeds that require so and are found at the NuGet.config file.
More info here
Notice that when the nuGet feed is within Azure DevOps there is nothing else required. If the feed is external you can configure at your Azure DevOps a nuGet Service Connections (at the link there is further info).
Use the built-in tasks for installing and running NuGet and you won't have authentication problems.
Use the dotnet task's restore command. If you're using a single Azure Artifacts feed, just select it from the dropdown in the task (instead of the PowerShell you mentioned). If multiple feeds (doesn't look like it from your question, but just in case), you'll need to check in a NuGet.config that references all of those feeds, then point the task to that config.
You may also need to pass the '--no-restore' flag to your 'dotnet build' command.
If you still encounter issues, ensure the correct build identity has access to your feed.