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

"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.

Related

Azure pipelines on a self hosted agent gives error NU1301: Unable to load the service index for source during dotnet restore

Having the same issue on a self hosted agent but I'm not specifying password in the yml. just specifying the vstsFeed
- checkout: self
submodules: true
persistCredentials: true
- task: NuGetToolInstaller#1
inputs:
versionSpec: 6.2.1
- task: UseDotNet#2
displayName: Using Dotnet Version 6.0.400
inputs:
packageType: 'sdk'
version: '6.0.400'
- task: DotNetCoreCLI#2
displayName: Restore Nuget packages
inputs:
command: 'restore'
projects: '**/*.sln'
feedsToUse: 'select'
vstsFeed: 'ba05a72a-c4fd-43a8-9505-a97db9bf4d00/6db9ddb0-5c18-4a24-a985-75924292d079'
and it fails with following error error NU1301: Unable to load the service index for source
Nuget feed is on another project of the same organization. I can see that pipeline produces a temp nuget config where it specifies username and password for this feed during run. Been breaking my head for the last 72 hours non-stop to find what is the issue. Azure pipelines and nuget sucks. 99% of the problems we had so far was with nuget not working smoothly with azure pipelines. Microsoft has to take a step back and resolve pipelines and nuget ssues.
Just to make sure: The NuGet feed is on the same Azure instance as the agent is registered with, right?
I remember similar issues on my on-premise Azure DevOps server, but also sometimes on the paid cloud variant. Sometimes it was flaky service state, sometimes the agent itself..
Kevin did give a good point with the permissions - if those are set, you're good to go from a permissions point of view - actually reader permission is enough for a restore - make sure to check the views panel too.
If after permissions check you still got issues, you might try my "just-making-sure-lines for your .yml file:
# NuGet Authentication (safety step, normally not required as all within the same organization/project)
- task: NuGetAuthenticate#1
displayName: "Nuget Authentication"
It shouldn't be required but I have it on all my pipes since I had such issues, and it reduced the occurence of the error line you posted in my cases (Hybrid devops architecture).
Another thing I ended up with is to specifiy the feeds explicitly in a repository-wide "NuGet.Config" file - and using this file within my yml files or with script lines instead of tasks now.
If nothing helps, enable diagnostics/verbose logging to get more error details. In the worst case: Log in to your agent machine, open a terminal in the same agent work folder and manually issue a dotnet restore command to see whats going on.
Post the additional results if still no progress.
Good luck
From your description, you are using the Nuget feed on another project of the same organization.
You need to check the following points:
Check the permission of the Build Service account.
Here are the steps:
Step1: Navigate to Artifacts ->Target Feed ->Feed Settings -> Permission.
Step2: Grant the Build service account Contributor Role . Build service account name: ProjectnamethePipelinelocated Build Service (Organization name)
For example:
Check the Limit job authorization scope to current project for non-release pipelines option is Enabled in Project Settings -> Settings.
If yes, you need to disable the option and then the pipeline can use the resource outside the project.
Note: To disable this option, you need to disable the option in Organization Settings-> Settings first. Then you could disable the option in Project level.

Azure pipeline build artifacts for previous builds

We have a .NET ASP Web form application. Currently we use TeamCity for the CI part. Deployment part is manual. We take the build artifact generated by TeamCity and deploy the artifact manually.
Now we will be using Azure DevOps for complete CICD process. During the POC we have been able to successfully build and deploy the application in IIS. I am new to the azure pipeline and doing POCs to learn it.
In TeamCity, against each build the generated build artifacts are available. So we can easily refer to any specific build and get the build artifact for that specific build. This is useful in case of rollback. We take the last successfully build artifacts and deploy the same in case of any error.
But in Azure is there any build artifacts repository where we can get the all the build artifacts for all the builds of that pipeline ? There is a section "Artifacts" but as per my knowledge this is for publishing as packages across feeds.
Now I have come across JFrog artifact repository https://jfrog.com/artifactory/. But no nothing about this. Need to go through.
Anyone can please let me know , in azure pipelines , where I can get all the build artifacts against all the builds in a pipeline. Is it available against each run in the pipeline or I need to configure it somehow ?
In any release failure , I need to rollback to the last successful deployed artifact version.
Thanks in advance for any guidance on this.
Azure Artifacts is feed source for packages like nuget etc.
And build/pipeline artifact you can find in your build here (of course if you published them):
Here you have documentation about publishing and downloading pipeline artifacts - newer and recommended approach and here about build artifacts
In short what you needs is add this step:
- task: PublishPipelineArtifact#0
displayName: 'Publish pipeline artifacts'
inputs:
targetPath: $(Build.ArtifactStagingDirectory)/
archiveFilePatterns: '**/*.zip'
Of course if your pipeline output is a nuegt package you can publish it to Azure Artifacts.

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

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 ?

Artifact not being downloaded in release pipeline - Azure DevOps

I've been struggling with an issue in Azure DevOps where I can build successfully an artifact through a build pipeline (I use the publish artifact task). I can see that the artifact is built successfully, as I can download it and I can reference it later in the release pipeline.
The issue is that when the hosted agent is started, no artifacts are downloaded to the machine, and my $(System.DefaultWorkingDirectory) is always empty. I am out of ideas on why in the initialization of the hosted agent, no artifacts are actually being downloaded....
I had the same issue this week. I set up my build with the 'Publish pipeline artifact' task and ran into the same issue as you, i replaced this with 'Publish build artifact' task in my build and everything worked out then.
I've read that 'Publish pipeline artifact' is only intended for uploading/downloading artifacts within the same pipeline, so thats why this won't get downloaded automatically in your release. Alternatively you could use the 'Download Pipeline Artifact' task in your release to explicitly download your artifact

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.