Download result of Azure Release Pipeline - azure

I have a release pipeline that combines two build pipelines artifacts to create the full release. I need to be able to download the result of this task after is done.
I run the Archive Task to zip the results but I don't know how to save it somewhere where I can download it using the Azure Pipeline agent.
Is there a task that can trigger that as a download or can I save it as an Artifact?
Thank you

Yeah, what you have to do is publish and then consume artifact in your Release pipeline. Here you have documentation
steps:
- publish: $(System.DefaultWorkingDirectory)/bin/WebApp
artifact: WebApp
Id you use Yaml then you should use this:
steps:
- download: current
artifact: WebApp
If you use Classic releases you needs to confgure it on designer.
Please use this task in your pipeline:
and then configure your release here:

Just realized that if I do this with my On-Prem agent I can get the file form the agent's file structure.
Would be nice though if I could get the file straight from Azure instead.
Thank you.

Related

Unable to deploy a .NET core app from DevOps to Azure using publish profile

I am creating a new Azure Pipeline to deploy .NET Core API app to an App Service in Azure. I am using connection type=publish profile in the pipeline, which is asking for a .pubxml file.
I have already committed the .pubxml file in my Azure repository.
But while giving the path for getting this .pubxml file, I am suspecting that I can't get .pubxml file through build artifacts. Is there any way to get the .pubxml file from azure repos to release pipeline?
I tried with $(Build.SourcesDirectory)\${{ parameters.Location }}\Properties\PublishProfiles\fcmapapi_Dev%20-%20Web%20Deploy.pubxml but no luck.
Any suggestions?
Step 1: Add Azure Repos / Build artifact with an alias to your release pipeline.
https://learn.microsoft.com/en-us/azure/devops/pipelines/release/artifacts?view=azure-devops#artifact-sources
https://learn.microsoft.com/en-us/azure/devops/pipelines/release/artifacts?view=azure-devops#artifact-sources---tfvc-git-and-github
Add "Build" resources as an artifact:
Add "Azure Repository" as an artifact:
Once, you have added both, the classic release pipeline will look like this:
Step 2: Use the three dots to browse the files / packages.

Script path of PowerShell task Azure DevOps release

I have PowerShell script, that I would like to use in deployments of Dynamics 365 to migrate an Access Team Template to our Test and Prod environments.
I have added the PowerShell script to the repository, and I would now like to add a PowerShell task to each of the stages in the deployment to migrate the Access Team Teamplate correctly in each of the environments.
However, I am not sure how to reference the path of the script in each of the stages in the release. When I click on the three dots to select the file, it is looking at the Linked artifacts - and not the repo.
If I add the PowerShell task to the pipeline, then I can select the script from the three dots.
Is it possible to reference the script in the release somehow?
You need to add your repository as a artifact or publish this script as artifact in the pipeline.
First, use Add an artifact and select the repository where you keep the script:
Then you will get the repo as a regular artifact.
Another way is to publish this script. To do that you need to check the repo in the pipeline which you already have produce your primary artifact and publish just this script. Then it will become available as you already have a defined source of artifacts.

Is it possible to download azure pipeline artifact to local folder within pipeline?

I have an Azure pipeline in which I create an artifact (a folder around 400 MB)
...
- task: PublishPipelineArtifact#1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifact: 'PublishArtifact'
publishLocation: 'pipeline'
Is it possible to download it to my local folder (let's say: C:\test) with a command within this same pipeline?
(I can download it manually if I go to Pipelines -> 'The latest build' -> Under Related, I have published artifact, but I want to do this automatically within pipeline with some command)
If you want to do it during pipeline execution you should install self hosted agent on your machine. Here you have links:
Self-hosted Linux agents
Self-hosted Windows agents
Then you need to condogure pipeline to use this agent.
Another option would be FTP upload. In this way you need to configure you machine as FTP server and use for instance this task. In this approach you can still use MS Hosted agent.
I think this should be possible if you add your computer as a deployment group (See Provision deployment groups). Then your build could trigger a classic Release pipeline where you can copy the artifact to a folder within you local machine
You can use Copy file task as explained in this doc
Copy file task

Is there a way to trigger pipeline using Azure Artifacts in YML?

When defining a GUI release I can make it be triggered by an Azure Artifact, is there a way to replicate this for pipelines in YML?
I am building in one AZDO tenant, pushing universal packages to another tenant, where the release definitions will be defined, I'm hoping this can be in YAML. But I don't see an obvious way to do this at the moment?
I see there is a design document that makes mention of packages, but no further details are provided
https://github.com/microsoft/azure-pipelines-yaml/blob/master/design/pipeline-resources.md
Cheers
Edit-
Is there a way to trigger pipeline using Azure Artifacts in YML?-But I don't see an obvious way to do this at the moment?
Yes, Yes. You are right !
That because the content in this document are speculative, designs, and future features.
If you check the upper level of design document you provided, there is a state:
Azure Pipelines YAML - Design Docs
The design docs within this repo are created at different times during
the development of Azure Pipelines, to support collaborative
contributions to the design process. Designs documents are for,
features considered for implementation but never implemented
already implemented features
future ideas for features
The design docs in this repo may not represent the current state
of an Azure Pipelines feature.
When you check the officially release document YAML schema reference-Resources, it only list:
resources:
pipelines: [ pipeline ]
repositories: [ repository ]
containers: [ container ]
So, Azure Artifacts source in YAML should be a future feature at this moment. Hope MS can achieve it one day earlier.
Hope this answer clear your question.
Build completion triggers are not yet supported in YAML syntax. After you create your YAML build pipeline, you can use the classic editor to specify a build completion trigger.
Reference:
https://learn.microsoft.com/en-us/azure/devops/pipelines/build/triggers?view=azure-devops&tabs=yaml#build-completion-triggers
Though i would suggest you to use below mechanism to trigger the release:
Resource triggers
Resources trigger will be helpful in below scenario:
I would like to trigger my pipeline when an artifact is published by ‘Helm-CI’ pipeline that ran on releases/* branch.
I would like to trigger my pipeline when an artifact is published and tested as part of Helm-CI pipeline and tagged as 'Production'.
I would like to trigger my pipeline when ‘TFS-Update’ pipeline has completed ‘Ring2’ stage so that I can run some diagnostics.
https://github.com/microsoft/azure-pipelines-yaml/blob/master/design/pipeline-triggers.md
Webhook triggers
At the end of the CI piepleing , you can add a task to hit webhook url which can trigger your CD is one way.
Hope it helps.
You can use a multi-stage pipeline to achieve this.
One stage would include a task that will push your artifacts to the feed. The next stage will contain other jobs that you want to be executed after pushing the Artifacts.
eg:
stages:
#Stage for preparing the Artifact
- stage: prepare
jobs:
- job: prepare
pool:
vmImage: xx
steps:
- task: PublishBuildArtifacts#1
inputs:
pathToPublish: xx
artifactName: xx
# Next stage in your pipeline
- stage: build
dependsOn: prepare
jobs:
steps:
- task: xx
Note that the second stage build dependsOn the stage prepare.
ps: Multi-Stage pipeline is currently under preview. If you enable it from the preview feature, you will also be able to see a nice visual representation of the stages.

How build artifacts are managed in Azure DevOps pipeline?

I am setting up a new Azure DevOps pipeline for my webapp. I can see that the build artifacts are saved in a path called $Build.ArtifactStagingDirectory. Where this path variable is pointing to and how long I can access my artifact?
Also, Does Azure DevOps versions(keep track of all the artifacts built over a time) the artifacts built? If no, how to version my build artifacts?
In the agent there are 3 folders: a, b and s. The variable $(Build.ArtifactStagingDirectory) point to folder a (artifacts), so the path is c:\agent\_work\1\a (if the agent location is c:\agent, the 1 can be another number also, according to how many builds there are, this number is incremental).
The artifacts not saved there! when you build the code all the code and the artifacts exist on folder s (sources), the best practice is to copy only the artifacts to folder a and then use the task "Publish build artifacts", in this task you take the artifacts from folder a and put them on Azure DevOps storage or in your file share (if you use self-hosted agent).
From the Azure DevOps storage / file share the artifacts exist according to your retention policy.
If you save the artifacts in Azure DevOps you can access your artifacts from the build summary page or create a release pipeline. if you save them in a file share you can just access them there or in the release pipeline.
You need to publish artifacts using task as by default they are not published. If you are using yaml just add
# Publish Build Artifacts
# Publish build artifacts to Azure Pipelines/TFS or a file share
- task: PublishBuildArtifacts#1
inputs:
#pathtoPublish: '$(Build.ArtifactStagingDirectory)'
#artifactName: 'drop'
#publishLocation: 'Container' # Options: container, filePath
#targetPath: # Required when publishLocation == FilePath
#parallel: false # Optional
#parallelCount: # Optional
There is configuration how long to keep those artifacts as i remember by default is 30 days and 3 or 5 last builds
You can control how many days you want to keep each build (default 30 days) before deleting it (See
Build and release retention policies). When a build is deleted, the published artifacts also gets deleted.
To version your build artifacts you can use the build number which will keep track.
Where the $Build.ArtifactStagingDirectory is pointing to depends on which publish location you are choosing. See Artifacts in Azure Pipelines

Resources