TeamCity Build & Deploy: How do you pass dependent artifact paths to a script? - deployment

How do you pass the artifact paths to a script in TeamCity.
The scenario is this
Build Project
Deploy Project (with an artifact dependency to #1)
Step 2 consists of a a script which
Stops a service (to unlock files)
Copies the build artifacts to the server
Restarts the service
I'm struggling with step 2, I figure I need to pass the path of the build artifacts into the script but I can't see how you do it?

We do something like this. It is not 100% clear but it looks like you want to do the build and deployment as two separate builds in TeamCity with an artifact dependency from the deployment build on the main build which is exactly what we do. Here is how we do it.
Setup your artifacts from the main build which it sounds like you have already done.
Example: **\bin\release\*.* => bin
Set up the artifact dependency (we also do a snap shot dependency as well but you don't have to) to pull your artifacts from the main build and put them into a local folder in your deployment build.
Example: Artifacts paths: bin\**\*.* Destination path: bin\
We use a mixture of MSBuild and PowerShell for doing the actual deployment work. In each case you can reference the artifacts using a relative path.
IF the build work folder looks like this:
root
|- bin (Artifacts pulled in from main build)
|- src
|- build (Where your build and deployment scripts live)
You would access the bin files from your deployment script located in the build folder like:
..\bin\[your files]
You can then pass the path to your build artifacts like this
%teamcity.build.checkoutDir%\bin\

Related

How to pick the correct path of artifacts after deploying to deployment group in 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

Adding files to build package artifacts

I'm following a learning course on plural-sight and he shows an artifact with cfg folder and json file within that folder(outside of the packge.zip file) but I cant figure out how he managed to configure his build process to get that file there.
How do I achieve this and where should i go to learn more about package files how they are made?
Everything in the "drop" folder gets included in the default "Publish Build Artifacts" Task, just add your files in the drop folder (or subfolders there).
The variable with the path is called: $(Build.ArtifactStagingDirectory)
This images shows a newly created "Publish Build Artifacts" task:
Something similar is probably creating your artifact, check for it in your build definition.

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

Exclude/Skip files in VSTS Build and release

We are in process of creating architecture for VSTS CI/CD to deploy our web app to our Azure App Services.
We want to exclude the web.config while deploying it to the Azure server as we are directly modifying the web.config on the different environment.
CI Tasks looks like this:
CI Taks
CD Task:
Deploy Azure App Service
I am aware of other ways of updating the web.config https://learn.microsoft.com/en-us/vsts/build-release/tasks/transforms-variable-substitution, but in our case we want to skip the web.config file.
I couldn’t find the option to skip file in during release in VSTS as mentioned in this thread
How do I exclude the .cs files within an artifact from a vs-team-services CI build?
Is there a way to exclude certain files while building and deploying the release?
Added -skip:objectName=filePath,absolutePath=web\.config in additional arguments. This skips updating the web.config file during deployment.
You can exclude the web.config before publishing artifacts in your build definition: copy the web packages files to a directory (such as $(build.binariesdirectory)), then copy the files exclude web.config to another folder (such as $(Build.ArtifactStagingDirectory)/package), and zip the files under $(Build.ArtifactStagingDirectory)/package. And finally publish the zip file as build artifacts.
Details changes in the build definition as below:
Change the MSbuild arguments as /p:OutDir="$(build.binariesdirectory)\\" in Visual Studio Build task.
Add a Copy Files task after Visual Studio Build task. Settings for this task as below:
Add Archive Files task after Copy Files task. And settings as below:
Change the Publish Artifacts task as below:
Now the build artifacts are exclude web.config file.
Additional arguments
-skip:objectName=filePath,absolutePath=\\Configuration\\AppSettings\\Base.config
you can add
-skip:objectName=filePath,absolutePath='.*\PackageTmp\Web.config$'
in Additional Arguments in "Deploy IIS WebSite/App" deployment VSTS task, this will not deploy your root web.config file.

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.