How to pick the correct path of artifacts after deploying to deployment group in azure devops - azure-devops

I deploy an artifact ZIP file and want to unzip it afterwards. The pipeline looks like this:
The first step downloads the artifact to this path:
C:\azagent\A2\_work\r2\a\worker-ASP.NET Core-CI\drop\worker.zip
but the zip Task looks for the zip file in this path:
C:\azagent\A2\_work\_tasks\Unzip_31f040e5-e040-4336-878a-59a473334434\1.2.3\*.zip
I know there are some hidden variables i can use to give the correct path to the unzip task. Where can i see the variables set for my release task and which one would contain "C:\azagent\A2_work\r2\a\worker-ASP.NET Core-CI\drop\" ?

The default artifact location is stored in one of these variables:
$(System.ArtifactsDirectory)/{artifact-alias}
$(Pipeline.Workspace)/{artifact-alias}
and artifacts are placed in a subdirectory with the artifact alias (the name you gave the alias).
See also:
https://learn.microsoft.com/en-us/azure/devops/pipelines/release/variables?view=azure-devops&tabs=batch#default-variables---general-artifact

Related

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 devops build pipeline

I have created a sample Website project with a single page having HellowWord.aspx and HellowWord.aspx.cs. I am trying to create an Azure DevOps build pipeline for this project. The following are the tasks I have added to my build package.
But the publish artifacts always contains the aspx and aspx.cs file. Not sure which tasks I am supposed to add to make the proper publish package. Which will create proper dlls for .aspx file instead of aspx.cs.
Publish build artifacts task has an argument Path to publish, which defines the folder or file path to publish. This can be a fully-qualified path or a path relative to the root of the repository. Wildcards are not supported. Variables are supported. Example: $(Build.ArtifactStagingDirectory). By default, this argument uses variable $(Build.ArtifactStagingDirectory).
So you need to check your Copy files task, to see what you have copied to $(Build.ArtifactStagingDirectory), and copy the correct files in this task.
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/copy-files?view=azure-devops&tabs=yaml

azure devops: copy file to artifact folder to access in release pipeline

I am creating a build for ios using azure and I want to copy a certificate file to artifact folder created to use in the release pipeline.
I am using a copy task and after the task is done its job, I am not able to find a copied file at the desired artifact folder. there are answers for copy task but not working for my scenario.
or is there any way to access files from the source folder of build pipeline to from release pipeline?
You were using download secure files task to download the cert files. As below described: see here for more information.
Once downloaded, use the name value that is set on the task (or "Reference name" in the classic editor) to reference the path to the secure file on the agent machine. For example, if the task is given the name mySecureFile, its path can be referenced in the pipeline as $(mySecureFile.secureFilePath). Alternatively, downloaded secure files can be found in the directory given by $(Agent.TempDirectory)
The secure files are downloaded to directory $(Agent.TempDirectory) and its path can be referenced by $(mySecureFile.secureFilePath) if you set the reference name to mySecureFile
So that the copy files task of yours need to be configured as below: Set the Source Folder to $(Agent.TempDirectory) and Contents to the name of the secure files. See below example:
You can also set the Contents to $(certFile.secureFilePath) $(provisionFile.secureFilePath) if you set the Reference name of above download secure file tasks to certFile and provisionFile
More conveniently you can use download secure files task directly in release pipeline to download the cert files.
Then the secure files will be available in release pipeline, and can be referenced just like in the build pipeline.

What is the path to access the downloaded artifacts in the release pipeline?

I have a .zip file as part of my published artifacts.
In my release pipeline, I am using a 'Powershell Script Task'. I need the path
to this zipped folder in my script.
When release pipeline is triggered, it copies over the artifacts:
Path to zipped folder: d:\a\r1\a\_DLR FOI\drop\packedSolution\dlrFoiSolution_managed.zip
How do I get the folder path d:\a\r1\a\_DLR FOI\drop\ in my PowerShell script?
$(System.ArtifactsDirectory) only returns upto d:\a\r1\a.
Try
$(System.DefaultWorkingDirectory)/_DLR FOI/drop/packedSolution/dlrFoiSolution_managed.zip
That should point to the release definition's artifact directory d:\a\r1\a . More variables here, or just add a suitable task (like copy) to release definition in editor, browse through the linked artifacts, and copy the path there.

Azure build pipeline - published zip file

I am fairly new to Azure Build pipelines, but I am having issues finding the answer to this.
When I build my artifact, the results include my server code files (vb and cs). How do I construct a build pipeline where the artifacts that are dropped are only the files I need to publish a site? Meaning, I want to exclude vb and cs files, but include necessary dll's and html/java script files.
You're publishing the wrong thing as an artifact. You're probably specifying $(Build.SourcesDirectory) or $(System.DefaultWorkingDirectory) as the root folder for your artifacts.
Look at your build step. Are you specifying an output directory as an MSBuild argument? If not, specify one. Specifically, $(Build.ArtifactStagingDirectory). So you'd pass the MSBuild argument /p:OutDir=$(build.artifactstagingdirectory)
Then publish $(Build.ArtifactStagingDirectory) instead of whatever folder you're currently publishing.