Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TeamCity pass parameter from server to build agent

I want to get commit count on build agent for manual versioning,

version = git rev-list --count "branchname"

git is not available on build agent because I have checkout "Automatically on server".

Is there a way to pass version from checkout server to build agent? (without changing VCS checkout mode to build agent)?

I'm running latest 9.1.6 version TC.

like image 965
Lev Avatar asked Mar 29 '16 09:03

Lev


People also ask

How do I add parameters to TeamCity?

Custom Build ParametersIn Build Configuration Settings | Parameters, project administrators can define build parameters for the current build configuration. As soon as a new build starts in this configuration, TeamCity passes these parameters to its build scripts and environment.

How do I authorize a build agent on TeamCity?

If a build agent is installed and running on the same computer as the TeamCity build server, it is authorized automatically. Agents are manually enabled/disabled via the web UI. The TeamCity server only distributes builds to agents that are enabled.

How do I link my TeamCity agent?

Installing via Windows installerIn the TeamCity web UI, navigate to the Agents tab. Click the Install Build Agents link and select Windows Installer to download the installer. On the agent, run the agentInstaller.exe Windows Installer and follow the installation instructions.

What is snapshot dependency in TeamCity?

By setting a snapshot dependency of a build (for example, build B) on another build's (build A) sources, you can ensure that build B will start only after build A is run and finished. We call build A a dependency build, whereas build B is a dependent build.


2 Answers

Is there a way to pass version from checkout server to build agent? (without changing VCS checkout mode to build agent)?

The short answer is that You cant do it.

What you can try and do is this:

- Add a version file to your repository,   
- **before** commiting use a git hook to update this file with the desired number
- Read the content of the file on your build server and you have it.

- Use a git hook to call a job on your build server which gets the 
  branch name and the number of commits and store it for later use somewhere

The main point is that since you cant do it you need to be little bit creative


Sample hook can be:

pre-receive hook

#!/bin/sh

branchName=$1

# Get the number of commits you need to store:
version = git rev-list --count $branchName

#############
# Now write the desired number to the desired file and let
# the build read it
#############

# Output colors
red='\033[0;31m';
green='\033[0;32m';
yellow='\033[0;33m';
default='\033[0;m';

# personal touch :-)
echo "${red}"
echo "                                         "
echo "                   |ZZzzz                "
echo "                   |                     "
echo "                   |                     "
echo "      |ZZzzz      /^\            |ZZzzz  "
echo "      |          |~~~|           |       "
echo "      |        |-     -|        / \      "
echo "     /^\       |[]+    |       |^^^|     "
echo "  |^^^^^^^|    |    +[]|       |   |     "
echo "  |    +[]|/\/\/\/\^/\/\/\/\/|^^^^^^^|   "
echo "  |+[]+   |~~~~~~~~~~~~~~~~~~|    +[]|   "
echo "  |       |  []   /^\   []   |+[]+   |   "
echo "  |   +[]+|  []  || ||  []   |   +[]+|   "
echo "  |[]+    |      || ||       |[]+    |   "
echo "  |_______|------------------|_______|   "
echo "                                         "
echo "${default}"

# set the exit code to 0 so the push will occur
exit 0;
like image 79
CodeWizard Avatar answered Sep 28 '22 07:09

CodeWizard


Basically, no, you cannot do what you want in a way you want it, you cannot just execute some command-line commands on the server when getting changes.

And why not just properly configure build number format and build counter and use them? It is also possible to set build number dynamically during a build.

like image 27
cyberskunk Avatar answered Sep 28 '22 09:09

cyberskunk