Share Single Downloaded Artifact for multiple deployment stage in Release - azure-devops

Using Azure Devops.
During Build Process artifact get published
During Release it get downloaded. Now I have multiple stage and each stage has different no of steps.
Now when Stage get change it download artifact again.
Also within stage there are different no of deployment task and some of them download it again.
I want to make it such a process so possibly single stage can download artifact only once.
I want if there is already such task present.

You can't. Each phase has to download the artifacts that it needs to use for one very simple reason:
They can run on different agents. Each agent definitely has a different working folder. Some agents may be on totally different machines. Some agents may be a totally different operating system. The release has no way of anticipating any of that.
There is no guarantee that Stage A-Phase 1 and Stage A-Phase 2 and Stage B will run on the same agent. They can run in parallel on different agents, or they can run sequentially on different agents. Or they can all run sequentially on the same agent.
Thus, if a phase needs an artifact, it has to download it.
If a given phase doesn't need certain artifacts, you can configure which artifacts it will download by clicking on the phase and unchecking the artifacts that are unnecessary.

Related

Download only artifacts I need in release pipeline and run tasks conditionnally

I have created a release pipeline that has multiple artifacts to be downloaded from multiple repositories.
Now, when I want to start the release I want to introduce a condition so that when the condition is met I download only the artifact I need and then run the task to deploy it otherwise when there is no condition all of the artifacts are downloaded thus all tasks are run.
How can I achieve that with azure DevOps ?
For conditions, I tried to look into
but for downloading only an artifact from multiple one I can't unless I specify a release pipeline for every project I have.
By default, build artifacts are downloaded to the agent. You can configure an option in the stage to skip the download of artifacts. https://learn.microsoft.com/en-us/azure/devops/pipelines/release/artifacts?view=azure-devops#artifact-sources---azure-pipelines
And use "Download Pipeline Artifact" task to specify your target Artifact. Set "Custom condition" within this task: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=classic
You can customize this behavior by forcing a stage to run by specifying a custom condition.

Is there a way to only run a deployment job if the downloaded artifact is newer than the one deployed in azure devops?

The current scenario is I want a Release Pipeline that has multiple artifacts (one function and several apis). Each one with a cd trigger except for the one to prod which is manual for right now.
In the pipeline is there a way to prevent a particular job from running if deployed pipeline is the same as the original?
For example, a change is made to one of the apis but the rest remain the same I would want the release to get created and deployed but only run the deployment job linked to that particular artifact.
The reason being is that for a deployment to production it would be nice to have all the artifacts I'm looking to deploy in one place and all I would have to do to deploy to prod would be hitting deploy and if the latest artifact is newer then the one deployed it gets deployed but if it is not that deployment would be skipped.
Right now each artifact is in a separate release pipeline and each gets deployed separately, which means we are keeping a separate document with a list of all the release pipelines that needing to be deployed for a specific set of changes.
Any direction would be appreciated, thanks in advance.
I think you can do that with multi-stages and triggers. You can follow these steps:
Create a release pipeline.
Add all your artifacts.
Create multiple stages. According to your requirement, you may need as many stages as your artifacts.
Set triggers for each stage. Click on the lightning icon to the left of the stage. In "Triggers", select "Afer release". Then enable the "Artifact filters". Choose the artifacts that correspond to this stage as the trigger. Here is an example:
Then your release pipeline will be look like this:
When an artifact changes, the corresponding stages will be triggered, and no other stages will run.
It doesn't work. If an artifact is changed it doesnt checked that the artifact is newer

Azure Devops Server: Share files between stages in Classic Release pipeline

In my Release pipeline I have 4 stages. All 4 of these stages need the same artifacts from the build pipeline. The stages also need the same files that the stages retrieve from an Storage account in MS Azure.
Currently every stage starts with retrieving the artifacts from the build pipeline(This is by default) and downloading the files from the Storage Account. These retrieving and downloading steps take quite some time.
1 Can I share files somehow between stages so the number of download and retrieve tasks are reduced? What is the best approach for this?
2 Is it possible to turn of the automatic retrieval of build artifacts at the beginning of a release stage?
You're already doing it the correct way. Every stage has the possibility of running on a different agent (or definitely running on different agents, in parallel), so downloading the necessary artifacts at the start of the stage is a requirement, since there's no guarantee that all stages will run on the same agent, or that rerunning a stage (say, in the event of a failed deployment) will reuse the same agent.
Yes. You can use artifact filters on any phase of a release to limit or eliminate the artifacts that are downloaded.

Where are the artifacts after having built, to be used by release?

I'm new to Aure DevOps. Trying to create build and release pipelines there's one thing I don't understand:
Commonly, every kind of build finally results in some output, called artifacts.
With Azure DevOps it seems like there is always a final copy or publish task necessary to copy the created artifact from A to B, so the release task may then access the compiled artifacts.
Why aren't these artifacts plain accessible to a release pipeline right from the location where they have been built? Why don't the build tasks automatically set a variable pointing to the right folder, so the release pipeline may access the files right from there?
Or is this already happening and I'm just missing something from the tutorials I watched?
There are so many reasons.
Two easy ones:
There is no guarantee that the agent's working folder still contains the files. Agents are reused from build to build and release to release, and a given build or release will always use the same working folder. The working folder is cleaned up between builds.
Releases may run on different agents. On different machines. In different domains. Or any combination. There's no guarantee that the agent where the build ran is accessible by the agent where the release is running. Publishing the artifact allows a guarantee: As long as the machine the release is running on has the ability to talk to Azure DevOps (which is a requirement for the agent to function in the first place), it can get the artifacts it needs.
Why aren't these artifacts plain accessible to a release pipeline
right from the location where they have been built?
Agree with Daniel.
The main reason for me is because we can't hold the hosted agent all the time. Since MS wants to protect resources efficiently, it is not occupied for a long time.
When we queue a build, MS will assign us a brand new clean agent to execute our task, and after the build is complete, the MS will reclaim the agent assigned to our build and restore the agent to its initial state in preparation for accepting the assignment of the next task.
So, we could not keep hold the hosted agent to use it in next release pipeline. We have to store the artifacts in the cloud/server, then we could download it in the release pipeline. Otherwise, we could not get the artifact we need from an agent that has been restored.
Besides, MS is randomly assigned to the agent, and we cannot guarantee that the same agent will be allocated and built during the release pipeline.
That is the main reason why we need to copy or publish the artifacts.
If you do not want to copy or publish the artifacts, you could setup your own private agent, and do not clean the agent before you execute the release pipeline.
Update:
why is the user, well, bothered to find a place for the artifacts
manually? I would have expected every build pipeline to come with a
personal space to store the latest build artifacts. A space where
Azure DevOps automatically copies the build artifacts to. To me it
looks like things have to be manually copied from A to B and then
later from B to C.
That because not all output is needed, for example, the test project, what we need is test result/Code coverage for the test project, not the output for the solution. In this case, we do not need to copy the output to the artifacts. On the other hand, we need to copy some special files to artfacts, then automatically copy the build artifacts will not meet your requirements.
That is also the reason why we provide the task to copy files to artifacts, so that we could customize our personality needs.
Of course, if you think that manual copying is superfluous, you can use the MSBuild parameter /p:output=$(build.artifactstagingdirectory) to set the output directly to artifacts.
If I need to copy things from A to B in the Build pipeline, then what
should keep me from copying it to C right away? Then a separate
Release pipeline would be, well, rather optional, if not redundant.
If you are in the build pipeline, there is another task Download build artifacts, which could download the build artifacts.
if you are in the release pipeline, you just need select the build artifacts as source, release pipeline will download that artifact automatically:
Check this document for some more details.
Hope this helps.

Azure Devops - How to prevent artifacts from being deleted after every agent phase?

I have a release pipeline that is specifically for running automated tests, that has multiple agent phases.
Most of the phases require use of the same artifacts in the same location on the build machine.
If I had an artifact set for download on a previous agent phase like so....
I used to be able to use that artifact again in subsequent agent phases, without downloading it again.
Now it appears to wipe the artifact folder contents when moving into a new agent phase. So if I have the following that follows the above....
The folder is wiped and the tasks that depend on that artifact existing fail.
Is there any way to prevent the build agent artifact folder from being deleted after an agent phase has finished and a new one starts?
Since phases can run in parallel and can go from one agent to another and since it's unknown what job will be next on that agent, the jobs clean up once they finish.
The trick is to end each phase with a "Publish Pipeline Artifact" task and then download that artifact in the next phase.