Azure pipeline yml: publish or file copy? - azure-devops

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.

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

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.

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.

CI_VSTS publish different web Artifact for each project in single solution

I have a CI pipeline(VSTS) in which I am able to build whole solution which has two website projects in it in a single artifact. What I want to do it build whole solution and then create publish artifact for each project.
e.g.
One artifact for Project_website1
One artifact for Project_website2
thanks. I tried similar topic in StackOverflow but didnt work for me
You can use two publish artifacts tasks and may be copy files multiple tasks to achieve any number of artifact in VSTS build. For example, say you have your current artifacts for a single project, comprising of _PublishedWebsites\MVS5WebApp (XCopy deployable website) and _PublishedWebsites\MVS5WebApp_Package (web deploy package).
If you want to separate these two, into two artifacts, you can use two Publish Artifact tasks as shown below, each one specifying exact path to publish (this path does not support wildcards, you just have to specify the folder you need to publish).
Result would be two artifacts
You can get more idea from the post here.
Also this post might be useful for you to understand more possibilities.
To publish the two websites projects’ artifacts separately, you just need to use two VS build tasks and two Publish Build Artifacts tasks to build and publish the two websites separately.
Such as the first VS build task and Publish Build Artifacts task are for website1, and the second VS build task and Publish Build Artifacts task are for website2. The detail configurations for each task as below:
VS build task for website1 (store the package for website1 in $(build.artifactstagingdirectory)\web1):
Publish Build Artifacts for website1 (publish website1’s artifacts from $(build.artifactstagingdirectory)\web1 to artifact web1):
VS build for website2 (store the package for website2 in $(build.artifactstagingdirectory)\web2):
Publish Build Artifacts for website2 (publish website2’s artifacts from $(build.artifactstagingdirectory)\web2 to web2):
Then you can get build artifacts for the two projects separately:
This is what I have done
As I am using my own agent
So the web projects are published in agent’s each project published directory.
That is directory a.
Solution:
All i did was after builidng the whole solution once vsts put all website in publish directory a.
I wrote powershell script to get each file for project and put it under subdirectory in published folder a.
E.g
Publish folder a will look like this after building solution
Website1.......xml
Website1.......zip
.
.
.
Website2........xml
Website2........zip
.
.
.
Etc
When solution is build the files will be in above folder togeter.
In order to build artifact for each project i wrote powershell script to put each project file in sub directory
E.g
a\website1
Website1.......xml
Website1.......zip
a\website2
Website2.......xml
Website2.......zip
Etc and so on
After that select each publish artifact for each directory and you can have artifact for each project.
Thanks

Unique Need - Perform Team Services releases using artifacts created in an external build

I have a unique need where I need to perform releases from Team Services using a Release Pipeline and artifacts that have been created in a previous external build. I have the artifacts that were created, dacpacs and websites ect.
I would like to deploy these items using the features in release Pipelines but artifact sources only come from a build or some other version control.
My approach (hack) was to use a build to copy the external files and publish them into the artifact container for the build. I could then use the release pipelines to do my releases. But .. Build copy tasks only seem to work with paths into a repo.
My fall back will be to use the release pipeline and powershell to do the releases with these externally created artifacts. I would sure like to avoid this since there is nice capability in the release pipeline tasks.
This is a compliance requirement my firm has which results in the rather crazy post.
Any help would really be appreciated.
You can use Copy Files task and Publish Build Artifacts task for your build definition.
Copy Files task
Source Folder: you can specify the folder which has your external build artifacts. Such as C:\project\a.
Contents: you can use wildcards to specify which files to copy. Such as **\*.dll, this will copy all *.dll files in C:\project\a and it’s subfilder.
Target Folder: where you want to copy these files. Usually it’s $(build.artifactstagingdirectory).
Publish Build Artifacts task
Path to Publish: set as the same with Target folder in Copy files task. Such as $(build.artifactstagingdirectory).
Note: Copy files task will find the source folder in the machine where the private agent is located.