Get branch name from TeamCity build - teamcity

I am deploying a nuget package which is a result of TeamCity Feature Branch build. The build number format I use includes branch name: 1.0.0.%build.counter%-%vcsroot.branch%.
I need branch name at Octopus Deploy side to customize my deploy. What is the right way to have branch name as a Variable?

We should be able to parse this out from the Package Name and set an Octopus Variable using something like this
Create the variable
Create a step to extract the NuGet (no features) and a PowerShell step
Use some PowerShell to set the variable by parsing the version number of that package
Hope this helps

Related

Pass/share parameter values between dependant builds in TeamCity

Setup: Build CD has has Artifact Dependency and Snapshot Dependency on Build CI. Build CI pulls from VCS root and generates artifacts for Build CD.
Problem: In Build CD I need %teamcity.build.branch% parameter, but it's not available, because it only uses artifacts and has no VCS Roots linked.
Question: Is there a way to pass parameters between dependant builds? (search results in the googles seem of topic)
Workaround 1: I can access %teamcity.build.branch% in Build CD if I link it to same VCS root Build CI is using, but I'd like to avoid having this link and Build CD unnecessarily pulling from VCS (build log shows it does this).
Workaround 2: I could write parameter to a file in Build CI and read from it in Build CD later. This is a hack and I would like to avoid it as well.
Absolutely. In CD, add a parameter called whatever, with value equal to %dep.Build_CI.teamcity.build.branch%. TeamCity will help you figure out the exact value thanks to its auto-suggestion/auto-completion, once you type %dep..

How to append git short hash into Octopus release from TeamCity

Using an OctopusDeploy: Create Release runner in TeamCity, I can create a release with the build.number fairly easily.
I'd like to add a suffix of the git commit short hash.
Here is how I solved it - scraped from various internet sources
In my CI Build, I added
A parameter named system.GitHashShort
Created a Powershell runner which executes this
$hash = "%build.vcs.number%"
$shortHash = $hash.substring(0,7)
Write-Host "##teamcity[setParameter name='system.GitHashShort' value='$shortHash']"
In my Deploy build configuration which is a snapshot dependency on CI Build
For the OctopusDeploy: Create Release runner, set the release number to be
%build.number%-%dep.MyAwesomeApp.system.GitHashShort%
This then gives builds of a format like 8.3.422.34-deadbee

Deploying to Octopus from Teamcity with .Net Core not creating .zip

I am doing the following steps:
dotnet restore
dotnet publish
octopusDeploy: Push packages
The second step creates a 'published-app' folder and the third step is meant to take that and create a .zip file and send it to the Octopus server.
The third step is connecting to the Octopus server but gives the error:
Running command: octo.exe push --server http://server.com/ --apikey SECRET
Pushing packages to Octopus server
Please specify a package to push
I am following this https://stackoverflow.com/a/38927027 so my third step has:
%teamcity.build.workingDir%/published-app/**/* => App.zip
Any ideas why the zip file is not being created?
Not sure if you ever got this working for yourself, however just in case it helps anyone we recently came across the same issue deploying an AspNetCore 2.0 web application running on net471 being built by TeamCity 2017.1.4 (build 47070).
After some tinkering I noticed that the "OctopusDeploy: Create and Push Packages" build step ran at our git checkout root directory, so I ending up having to use the following values for the "Package path patterns"
%ProjectDirectory%/published-app/**/* => %ProjectName%.%GitVersion.NuGetVersion%.zip
NB: %ProjectDirectory%, %ProjectName% and %GitVersion.NuGetVersion% are build parameters we have manually defined elsewhere in the build process that TeamCity can replace. %ProjectDirectory% is simply the application's source directory relative to the root of the git checkout i.e. WebApplication1 so the full path would be <full checkout path>/WebApplication1
Another gotcha that we experienced was that at the time of writing the combination of TeamCity and octo.exe (from Octopus.TeamCity v4.15.10) didn't like creating nupkg files, so make sure you try to produce a ".zip" file. In the error instances we would receive the following error:
Error from Octo.exe: Cannot run program "C:\BuildAgent\temp\buildTmp\octo-temp\3.0\octo.exe" (in directory "C:\BuildAgent\work\4e62985fa616fa1f"): CreateProcess error=206, The filename or extension is too long

How to get ${buildNumber} in TFS with Maven?

I need to add the buildNumber in my generated manifest file with Maven. We use TFS(Team Foundation Server) as our repository. Is there any way to access it?
Below link explain the how get build number with Git, SVN or Mercuria.
http://www.yegor256.com/2014/07/03/how-to-read-manifest-mf.html
I also need the same thing with TFS?
You can use ${env.TF_BUILD_BUILDNUMBER} environment variable to get TFS build number.
Please have a check on this link: https://blogs.blackmarble.co.uk/blogs/rfennell/post/2014/12/16/Setting-a-build-version-in-a-JAR-file-from-TFS-build.aspx
I think the correct variable number is env.TFS_CHANGESET or just TFS_CHANGESET. It worked for me.
Predefined variables in TFS:
Build.SourceVersion - Git: The commit ID.
BUILD_SOURCEVERSION - TFVC: the changeset.
A list of all variables here:
https://www.visualstudio.com/en-us/docs/build/define/variables

Azure Octopus Deploy Ignoring PostDeploy.ps1

I am trying to run a PostDeploy.ps1 script using an Azure deployment. The nuget package has the PostDeploy.ps1 file in it, but the script is never run.
Why might this be? The only line in the script is currently:
Write-Host "Test Custom Deployment Script"
This text never appears in the log.
Have you checked this location C:\Octopus\Applications.Tentacle\Packages to verify that the latest package has been downloaded?
I had an issue using Octopus and Teamcity where the artifacts view stated that the PostDeploy.ps1 had been added to the nuget package, but when I checked that location it wasn't there.
Octopus can cache the packages so check your timestamps and version numbers to ensure that the most up to date version of the package is being used. Could it be that an earlier version of PostDeploy.ps1 didnt have the
Write-Host "Test Custom Deployment Script"
line in it and that is the one that octopus is using during deployment?

Resources