How to use git on a continuous integration build server

We have a build server that is designed to check the version of code from git and build. As a rule, the server will check and build the develop branch, but it can be controlled using the graphical interface to build any specific branch or tag.

Our git archive is large, so we want to run git clone only once. So my question is: what sequence of git commands should be issued in order to update the current working directory with respect to the remote git archive.

My initial naive attempt just did git checkout <branch> and then git pull . But this did not take into account all the artifacts created by the previous assembly that needed to be deleted, as well as some automatic code modifications performed by the assembly process, for example. version numbers in assembly files.

So, it seems to me that we need a sequence of commands for

  • Get rid of any changes in the local directory
  • Update your local repository to enable ALL commits from the remote server.
  • Place an order on the named branch or tag

Please keep in mind that the specified branch or tag may not yet be known in the local repository. For example, if a new branch release/xxx is created on the remote server, this will not be known a priori to the local build machine. This is another of the problems that my naive approach came across.

And finally, it is possible that the git server can sometimes correct the history. I am sure that this will be a rare event, but it would be desirable if the integration server did not need to be configured after overwriting the history.

Many thanks

+8
git continuous-integration
source share
2 answers

This is the mechanism we are currently using. git clone is executed only once as part of the setup, and then the following is done for each build.

I removed the error handling for clarity.


 # Undo any modifications made to the working tree by the build process git reset --hard # Remove any untracked build artifacts created by the build process git clean -fdx # Fetch all commits and new branches/tags from the git server. git fetch # Set the index and working directory to the required tag or branch. # Notes: # * If the last build was for the same branch, then this will not # update the working directory. # * The %TAG_OR_BRANCH% variable is passed in via the GUI. This will # be in the form of a branch name (develop|release/vX.XX) or a tag (vX.XX) git checkout %TAG_OR_BRANCH% # Bring the index and working tree up-to-date. # Notes: # * the --ff-only flag is probably redundant, but we want to make it # clear that no merging is expected. git pull --ff-only 

We created new tags / branches on the developer's machine, dragged them to the server, and this script correctly extracts them and builds the results. We experimented with adding the origin/ prefix to the names of the branches or tags, but this approach did not work for us (the tag names were not recognized).

I think the main difference between this script and the much simpler answer suggested by @Yasser is that git HEAD points to the right place, and the git status command gives a reasonable answer. Regardless of whether this is important or not, I'm not sure.

+2
source share

Assuming you configured .gitignore , you should just do

 git fetch git reset --hard origin/branch git clean -xfd 

This should produce a clean build.

+4
source share

All Articles