Deploy a specific revison based on pinned build using MSBuild in TeamCity - msbuild

My setup in TeamCity:
I've got a "CI configuration" running a singular build step that uses a MSBuild script checked-in to the from the project. The configuration has a number of sub targets such as unit tests, deployment to test site etc.
I also have a "Deploy configuration" with a singular target using another MSBuild script that only does deployment (using msdeploy). This is triggered manually.
My problem:
The "Deploy configuration" need to deploy a revision based on the latest pinned build from "CI configuration". The whole idea is essentially to get a one-click-deployment functionality based on latest pinned build in CI. Does anyone know how to do this in MSBuild using TeamCity?
Im guessing I need to use "Snapshot Dependencies" to get the latest pinned revision, but I have not been able to figure out how to deploy that snapshop in the MSBuild script.
Also I'd like to specify that I would like to do this within MSBuild script and not by using the "Custom build" dialog in TeamCity.

Ok, figured it out on my own.
You need to set a row in the "Artifacts path" like so "*/ => source" in the CI configuration.
Then add a "Artifact dependency" in the Deploy configuration pointing to the CI configuration in the "Depend on" select and set "Get artifacts from" to "Last pinned build" and then point to the "Artifact rules" like so: "source => source".
And at last, inside my MSBuild file, I added "/source/", to my project path in the Target-node with the deploy.
Works like a sharm every deployment. :-)

Related

VSTS Test Assemblies - No test assemblies found

I'm attempting to run some selenium tests in my solution that are in a project called SA.SEPA.Web.UI.Selenium as part of a build definition in VSTS, but it is failing to run the Visual Studio Test task with the error...
No test assemblies found matching the pattern: **\*Selenium*.dll.
Search folder is set to - $(System.DefaultWorkingDirectory)
Preceding tasks are a nuget restore and build solution
Can anyone help?
You are specifying $(System.DefaultWorkingDirectory) as the search folder. By default (unless overridden), this points to the Source folder on the Agent.
If you are instructing MSBuild (using the OutDir parameter) to output your assemblies in a specific location then you should use that location.
Edit: If this is an On-premises Agent, it should also be running in interactive mode (not service) if you want to execute any UI tests
I ran into this same error but it was a different cause, so I'm adding my solution here.
I was getting the "no test assemblies found" error when trying to run Selenium tests with VSTS as part of a build.
My problem turned out to be that the test assemblies were not checked into change control (git, through VS2017), and therefore were not part of the build. The folders that contain the test assemblies were ignored during my original check-in by default. Once I added those folders to my repository, the build could find the tests and run them.

How to access artifacts folder after build in TFS online?

PreInfo: I have .net core web api (vs2015) mixed with just ordinary projects.
I have spent almost 2 days now to get this to work and search and tried everything I can think of, but I just cant for the live of me get the build and release in TFS online to play together.
The build (publish artifact step) says "Directory 'D:\a\1\a' is empty. Nothing will be added to build artifact 'drop'."
but the "run dot net" step says
"Published to D:\a\1\s\Operator\MobileService\root\MobileService\src\AMP.Operator.MobileService\bin\release\net452\win7-x64\publish"
...so it must be somewhere the release can pick it up but no matter what I try I can´t get it to be picked up.
Here is my build setup
dotnet run
publishing
And the realse with $(System.DefaultWorkingDirectory)/MobileService-Dev please note that I have tried every combo of $(build.artifactstagingdirectory) in the build to publish without luck but I sure this should point to the publishing folder for the build
I so hope somebody can point me to a solution. I just can´t understand how hard it is to make this work..
Within your build definition, I recommend adding a Copy Files step that will copy your the build artifacts from your msbuild results to the Build's Artifact Staging Directory before you run the Publish Artifact step.
Source Folder: $(Build.SourcesDirectory)
Contents: **\bin\$(BuildConfiguration)\**
Target Folder: $(Build.ArtifactStagingDirectory)
I am assuming that the $(BuildConfiguration) variable is custom to your definition and is probably Debug or Release. I am not sure what exactly the Run dotnet step does, but this build definition I setup published my build artifacts correctly. The Publish Build Artifacts step I'm running has the same steps as yours, except the only control option enabled is Enabled.
I am also running on TFS 2015 update 2.
You can download the files if you just want to take a look at them. Go to the build, click on the Artifacts tab, and then download as shown below:
You need to specify output argument (--output/-o) for dotnet publish command.
Arguments:
Publish -c $(BuildConfiguration) -o $(Build.ArtifactStagingDirectory)
BTW: You said “run dot net” step says “Published to D:\a\1\s....”, the files are in D:\a\1\s, no files in D:\a\1\a (one is s and another is a).

Replicate msbuild command from TeamCity

I have a TeamCity build which uses msbuildbootstrap to run msbuild. I want to run the same msbuild command on my local machine, but I don't know what parameters TeamCity is passing it. The logs don't say.
[Step 1/3] Starting: D:\BuildAgent\plugins\dotnetPlugin\bin\JetBrains.BuildServer.MsBuildBootstrap.exe /workdir:D:\BuildAgent\work\e8f57dfa2eca8e8c /msbuildPath:C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
[14:10:12][Step 1/3] in directory: D:\BuildAgent\work\e8f57dfa2eca8e8c
[14:10:14][Step 1/3] depot\Build\Scripts\release.build.teamcity: Build target: PublishRelease (1m:10s)
[14:10:14][depot\Build\Scripts\release.build.teamcity] PublishRelease (1m:10s)
[14:10:14][PublishRelease] CreateCustomBuildLabelTask (1s)
[14:10:15][CreateCustomBuildLabelTask] Creating custom build label from TeamCity build number 7375.
[14:10:15][CreateCustomBuildLabelTask] Generated build label is 2016.02.01.ReleaseCandidate
[14:10:15][PublishRelease] CopyBuildArtifactsTask (5s)
How can I exactly replicate the parameters TeamCity passes to msbuild? Is there any documentation for msbuildbootstrap?
That's a tough question, because TeamCity does not only send a list of properties as an input for the MsBuild command. It creates a list of environment variables that will be taken into account by MsBuild itself as properties.
You can find the defined environment parameters in the "Parameter"s section of your build configuration in TeamCity. They are referenced as "System Properties (system.)".
Once a build has been executed, you can find again the list of system properties in the build result tab named "Parameters" under "System properties".
As a build manager, I don't like this situation, as it can be pretty hard to reproduce a build on a local machine. We use too many system properties today, only specified in TeamCity. I want to shift us to a clear API for executing our builds.

Run a build step on a specific branch only

I have a build configuration containing two build steps "Build" and "Deploy".
This build configuration is using a Git VCS and is configured to run all branches.
Let's assume that I currently have two branches "master" and "Feature in Development".
I want to divide the "Deploy" step into two. "Deploy Production" and "Deploy Beta".
The "Deploy Production" step should only be executed when the master branch was changed and is currently building.
Is there a built in possibility to do that or do I have to check the %teamcity.build.branch.is_default% variable manually within the script?
It seems that JetBrains added this feature in TeamCity v9.1.
For v9.0 I used a Powershell script and checked '%teamcity.build.branch.is_default%' -eq 'true' build property.
You can add a condition to a build step in TC using the dropdown:
Why not create a two build configuration for that, one checking code from master, second from branch? IMHO it should not be steps in the same build as they are not chained.

TeamCity + MSBuild: Tagging a deployment with a VCS build number

I am using TeamCity 4.5.1 to build and deploy an ASP.Net application to development.
This is working perfectly so far, however, my manager has asked that I tag the folder with the specific SVN Revision from which the source was compiled.
I am using an MSBuild script to do the build and deployment, however, I am unable to successfully retrieve the build number.
Here is the MSBuild command I'm using (sanitized):
<Exec Command=">\\server08\D$\Websites\MYPROJECT\version.txt echo %env.BUILD_VCS_NUMBER%,%env.BUILD_VCS_NUMBER.1%,%system.build.vcs.number%,%system.build.vcs.number.1%,%system.build.number.format%,%system.build.number.format.1%,%system.build.vcs.number.MYPROJECT_Web_Root%,%env.TEAMCITY_VCS_NUMBER_MYPROJECT_Web_Root%" />
Version.txt turns up like this:
,,,,,,,,
Aka, empty. What am I doing wrong? Any better way to do this?
%env.XYZ% is TeamCity's method of referring to the environment variables, if you want to use them in ITS settings anywhere.
In a batch file or via msbuild, you only want the XYZ part.
echo %BUILD_VCS_NUMBER% > \\path\to\version.txt