TeamCity pass parameter from the server to create an agent

I want to get a commit counter for a build agent for manual versioning,

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

git not available in the build agent because I have a "Automatically on server" check.

Is there a way to pass version from a validation server to create an agent? (without changing the VCS checkout mode to create the agent)?

I am using the latest version of TC version 9.1.6.

+6
source share
4 answers

Is there a way to transfer the version from the verification server to create the agent? (without changing the VCS verification mode to create the agent)?

Short answer: You cannot do this .

What you can try is:

 - 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 thing is that since you cannot do this, you need to be a little creative


Sample capture 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; 
+2
source

Basically, no, you cannot do what you want, as you want, you cannot just execute some command-line commands on the server when changes are received.

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

+2
source

I really like things to collect the current branch name and git hash at build time. Unfortunately, no, you cannot run these git commands during build with the validation mode installed on the server. You need to change the scan mode to create the agent to ensure that the .git folder exists in the working directory. Upstairs, I see no harm in this. It does not copy remotes, so it would be very difficult for the build agent to make changes to the main repository.

At @hexct, rebase or merge or any number of things can make this account unreliable. Better bind yourself to the git hash than to the # of commits.

+2
source

Why do you even need a git counter?

The easiest way is to follow the principles of TeamCity. Use TeamCity counter instead of git counter. Install the assembly trigger after each commit. And set the label to git to view build versions in git history.

+1
source

All Articles