Azure Devops Multi-Stage Yaml Pipeline - "Could not find any file matching the template file pattern" - azure-devops

I am converting a classic Build and Release Pipeline to a Multi-Stage Yaml pipeline in Azure Devops.
I keep getting a "Could not find any file matching the template file pattern" error from my Multi-Stage-Pipeline in the Release Part.
Build Part
Release part

In the build part you published the artifact to the pipeline workspace, so you should reference this path in the release part. Use $(Pipeline.Workspace) instead of $(Build.ArtifactStagingDirectory) in the csmFile and csmParameterFile. That should solve the issue and is the cleanest solution without an extra download artifact step.

My bad - needed to download artifact first

Related

Azure Release Pipeline failed to download the template file from the given path

I'm creating a release pipeline and it should be picking up the ARM Templates from my built artifacts but it keeps giving the below error. I'm not sure what I'm doing wrong here
The way this has been configured is:
1. Artifact is picked up from my build pipeline:
2. Build pipeline has successfully created the artifact:
3. Artifacts are selected here
Any help would be much appreciated
EDIT:
Have changed my CI pipeline to use PublishBuildArtifacts but not getting an error about 2MB limit:
I reproduced your issue when i used the task PublishPipelineArtifact#1 to publish aritfact in build pipeline.The same warning poped up when i selected Override template parameters. Then i changed the task to PublishBuildArtifacts#1 and it worked.
RESULT
You can refer to this doc to understand the two types of publish artifact task:
PublishBuildArtifacts
Publish Pipeline Artifacts
Here are suggestions to check:
1 check the type of publish artifact task in your build pipeline.
2 check your template that should follow Syntax and expressions in ARM templates
Managed to do using PublishBuildArtifacts and linked ARM templates to overcome the 2MB issue: learn.microsoft.com/en-us/azure/data-factory/….

Accessing Published Artifacts from yaml pipeline tasks

I have a PowerShell task that processes published artifacts from another stage.
I have noticed these are put into a folder "s". Random sampling shows its "s" all the time but I doubt if it will be the case always!
Wondering what's the best way to refer to these files safely?
Here's my publish artifacts task:
Published artifacts:
And the PowerShell task that consumes these artifacts:
The variable that you use does not work with the s folder. As described on the documentation Build.ArtifactStagingDirectory is the local path on the agent where any artifacts are copied to before being pushed to their destination. For example: c:\agent_work\1\a . You will find those files under a folder. The folder that is referred with the s letter is where the sources are downloaded Build.SourcesDirectory.
https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml
Documentation on Azure devops predefined variables that can be used and where the folders are located.
https://blog.geralexgr.com/devops/how-azure-devops-pipelines-agent-works
The predefined variable you are looking for is $(Pipeline.Workspace). If you look at the documentation for the download pipeline artifact task you can see the default path. Note if you are downloading more than one artifact they will be within subfolders
Edit - Having just looked again at the pipeline are you publishing and downloading the artifact, or are you just doing all of these tasks as a single pipeline?
The best way imo to have these setup would be to have two pipelines. The CI to build and publish the artifact, then the CD pipeline to download and use the artifact

Azure pipeline yml: publish or file copy?

At the end of my pipeline I want to copy the bin directly to a network share from which it can be used to deploy.
I see there are two possible task typed that could do this:
copy files that makes a task: CopyPublishBuildArtifacts#1; or
_ copy and publish build artefacts_ that makes a CopyPublishBuildArtifacts#1.
And this publish is different to dotnet publish?
Which one should I pick and why?
They appear to have identical parameters.
What is the # for?
Azure pipeline yml: publish or file copy?
The task CopyPublishBuildArtifacts is deprecated. If you're using Team Foundation Server 2017 or newer, we recommend that you use Pipeline Artifacts.
And if you want to know the different between publishbuildartifacts vs publishpipelineartifact, you could check below thread for the details:
What is the difference between Build Artifact and Pipeline Artifact tasks?
And this publish is different to dotnet publish?
The answer is yes. The dotnet publish task is to serve the specific project. Its function is similar to that we choose the Publish option for net core project in Visual Studio.
But we could specify the folder or files to publish for the publishbuildartifacts or publishpipelineartifact task.
Which one should I pick and why?
We recommend to use the publishpipelineartifact task if you just want to copy the bin directly to a network share.
You could check the reason from here:
For build artifacts, it's common to copy files to $(Build.ArtifactStagingDirectory) and then use the Publish Build Artifacts task to publish this folder. With the Publish Pipeline Artifact task, you can just publish directly from the path containing the files.
By default, the Download Pipeline Artifact task downloads files to $(Pipeline.Workspace). This is the default and recommended path for all types of artifacts.
File matching patterns for the Download Build Artifacts task are expected to start with (or match) the artifact name, regardless if a specific artifact was specified or not. In the Download Pipeline Artifact task, patterns should not include the artifact name when an artifact name has already been specified. For more information, see single artifact selection.
What is the # for?
The role of # is to specify the version of the task. For example, #1 is to use the version 1.0 of the task.

The $(Build.ArtifactStagingDirectory) variable's value changes when deploying a build in Azure DevOps Pipelines

I have a DACPAC deployment task which is failing, because for some reason the value of the $(Build.ArtifactStagingDirectory) pipeline variable is changing between the build pipeline and the release pipeline. In the build pipeline, the variable is set to C:\agent\_work\2\a, but in the release pipeline it's C:\agent\_work\r2\a. This is causing the release pipeline to fail when it tries to deploy the DACPAC artifact, because the folder it's looking in is empty; the folder where the artifact actually is is ignored. How do I make these variables consistent between the build and release pipelines so that the artifact is retrieved from the same folder it's generated in? These variables appear to be built in, so I don't see any way to change them. I could always hardcode a path, but that seems a bit kludgy...
In releases you have System.ArtifactsDirectory which is
The directory to which artifacts are downloaded during deployment of a release. The directory is cleared before every deployment if it requires artifacts to be downloaded to the agent. Same as Agent.ReleaseDirectory and System.DefaultWorkingDirectory.
Example: C:\agent_work\r1\a
and in pipelines/builds Build.ArtifactStagingDirectory
The local path on the agent where any artifacts are copied to before being pushed to their destination. For example: c:\agent_work\1\a
A typical way to use this folder is to publish your build artifacts with the Copy files and Publish build artifacts tasks.
Note: Build.ArtifactStagingDirectory and Build.StagingDirectory are interchangeable. This directory is purged before each new build, so you don't have to clean it up yourself.
See Artifacts in Azure Pipelines.
This variable is agent-scoped, and can be used as an environment variable in a script and as a parameter in a build task, but not as part of the build number or as a version control tag.
This is in line with your experience. And you cannot change it, as they are predefined. But can you clarify why this is a problem for you?
In the release pipeline, you can't directly access the files in the build pipeline, not only because the working directory is different, but also because they do not use the same agent. You need to download the artifacts first, and then use them in the release pipeline.
You can use the following ways to download artifacts:
Use the Download Build Artifacts task.
Go to the edit release pipeline page -> Select Add artifact -> Select Build -> Fill in the information related to the build pipeline (Notice the value of Source alias)-> Add it. You will find your artifacts are downloaded in $(System.ArtifactsDirectory)/${Source alias}
For more information about consuming artifacts in release pipelines, you can click this document.
Oh, I think I figured it out. Each release pipeline stage has an option called "Artifact download" which lets you specify which artifacts out of all those linked in the pipeline are actually used by that stage. I needed to check the appropriate checkboxes there in order to use the artifacts in the stage's tasks.

.NET Core WebJob Console App CI/CD using Azure DevOps Pipelines

I'm trying to build my console application through Azure DevOps. So to this I'm following this tutorial.
The follow images, are from what I already did.
Build Solution Pipeline
Build Solution Pipeline / Publish
Build Solution Pipeline / Artifact
Deploy WebJob Pipeline
Deploy WebJob Pipeline / Variables
When I run the Build Solution the zip seems to work, because I see it.
But when I run the Deploy WebJob Pipeline I get ##[error]D:\a\1\s\***.zip not found.. I tried wwwroot/App_Data/jobs/, but still the same error.
What could I be doing wrong? What's the right way to set the zippedArtifactPath?
You're following the tutorial incorrectly. The tutorial is telling you to create a release. You're using a build pipeline to try to release. Although you can do that, you shouldn't.
You have two options:
If you want to keep using the visual designer, use a release. Look at the "Release" tab for this. Releases can be tied to build artifacts and will handle downloading the build artifact automatically.
If you want to use YAML, refer to the YAML documentation and set up a multi-stage pipeline to release.
What could I be doing wrong?
Check your error messgae ##[error]D:\a\1\s\***.zip not found we can find in the second build pipeline, the PS tried to get the xx.zip in xxx\s folder while in first build pipeline you published the xx.zip to xxx\a folder.
The $(System.DefaultWorkingDirectory) for build pipeline is xx\s folder while that for release pipeline is xx\a folder. In first build pipeline we published the xx.zip to Build.ArtifactStagingDirectory which is a xx\a folder, so we can't access the xx.zip from xx\s folder in second build pipeline's PS script.
What's the right way to set the zippedArtifactPath?
It's not recommended to build and deploy one web app using two build pipelines. For normal logic, we should do this by using combination like build+release pipeline just like the Toturial and Daniel suggests above.
We can use this variable $(Release.PrimaryArtifactSourceAlias) to get the artifact directory.
In your powerShell script you can set path variable like:
$path = "$(System.DefaultWorkingDirectory)\$(Release.PrimaryArtifactSourceAlias)\webjobs_drop\[ZIP_File_Name].zip"
[your build artifact name]\webjobs_drop[your zipped files].zip
"your build artifact name" - you should get it from your release pipelines Artifacts stage from where you are selecting your build artifacts