{"id":183,"date":"2010-06-20T01:30:00","date_gmt":"2010-06-20T07:30:00","guid":{"rendered":"https:\/\/www.chrisedwards.dreamhosters.com\/blog\/2010\/06\/21\/extreme-ci-part-2-setting-up-git-for-a-personal-ci\/"},"modified":"2010-07-07T07:23:37","modified_gmt":"2010-07-07T13:23:37","slug":"extreme-ci-part-2-setting-up-git-for-a-personal-ci","status":"publish","type":"post","link":"http:\/\/architester.com\/blog\/2010\/06\/20\/extreme-ci-part-2-setting-up-git-for-a-personal-ci\/","title":{"rendered":"Extreme CI Part 2: Setting up Git for a Personal CI"},"content":{"rendered":"<p><em>How I run a personal CI build every time I build my code in Visual Studio.<\/em><\/p>\n<h2>Summary<\/h2>\n<p>This week we setup Git so it commits your changes and pushes them up to the personal CI server. We\u00e2\u20ac\u2122ll also create a batch file to automate this process. In part 3 we\u00e2\u20ac\u2122ll create the Visual Studio macro that automatically runs the Personal CI process every time you build your code.<\/p>\n<h3>The Series<\/h3>\n<p>In this series I show you how to take continuous integration to the extreme by building a personal CI server that runs all your tests and adds a commit to source control every time you build in Visual Studio.<\/p>\n<ul>\n<li><a title=\"Extreme CI Part 1\" href=\"https:\/\/www.chrisedwards.dreamhosters.com\/blog\/2010\/06\/13\/extreme-continuous-integration-a-personal-ci-build-for-visual-studio-part-1\/\" target=\"_self\">Extreme CI Part 1 \u00e2\u20ac\u201c Overview<\/a><\/li>\n<li><strong>Extreme CI Part 2 \u00e2\u20ac\u201c Setting Up Git <em>(you are here)<\/em><\/strong>\n<ol>\n<li>Setting up the personal CI Git repository<\/li>\n<li>Adding it as a remote to your working repository.<\/li>\n<li>Creating a batch file to automatically commit and push to the remote personal CI repository.<\/li>\n<\/ol>\n<\/li>\n<li><a title=\"Extreme CI Part 3\" href=\"https:\/\/www.chrisedwards.dreamhosters.com\/blog\/2010\/06\/21\/extreme-ci-part-3-the-visual-studio-macro\/\" target=\"_self\">Extreme CI Part 3 \u00e2\u20ac\u201c The Visual Studio Macro<\/a><\/li>\n<\/ul>\n<p>Lets get to it.<\/p>\n<h2>Create the Personal CI Git Repository<\/h2>\n<p>The CI Server will get code changes from a Git repository. It will monitor this repository, and when changes are committed, it will pull them, build the code, and run the tests. Let\u00e2\u20ac\u2122s create the repository.<\/p>\n<p>For this example we\u00e2\u20ac\u2122ll keep it simple and create the repository in a new folder our local machine. In reality, you may want to put this on another machine.<\/p>\n<blockquote><p><code>C:\\Projects&gt;<strong><span style=\"color: #000000;\">md MyProjectPersonalCI.git<\/span><\/strong><\/code><\/p>\n<p><code>C:\\Projects&gt;<strong><span style=\"color: #000000;\">cd MyProjectPersonalCI.git<\/span><\/strong><\/code><\/p>\n<p><code><strong><span style=\"color: #000000;\"> <\/span><\/strong><\/code><\/p><\/blockquote>\n<p>Since this repository will only be accessed remotely, it doesn\u00e2\u20ac\u2122t need a working directory\u00e2\u20ac\u201dso we will use the <code>--bare<\/code> switch when initalizing it to tell Git not to create one.<\/p>\n<blockquote><p><code>C:\\Projects\\MyProjectPersonalCI.git&gt;<strong><span style=\"color: #000000;\">git --bare init<\/span><\/strong><\/code><\/p>\n<p><code>Initialized empty Git repository in C:\\Projects\\MyProjectPersonalCI.git\\<\/code><\/p><\/blockquote>\n<h2>Add the Personal CI Repository as a Remote<\/h2>\n<p>To push changes to the personal CI repository we need to add it as a <em>remote<\/em> to our local working repository. To avoid conflicts with developers using \u00e2\u20ac\u0153origin\u00e2\u20ac\u009d, we\u00e2\u20ac\u2122ll give it the name \u00e2\u20ac\u0153personalci\u00e2\u20ac\u009d. How descriptive.<\/p>\n<blockquote><p><code>C:\\Projects\\MyProjectPersonalCI.git&gt;<strong><span style=\"color: #000000;\">cd ..<\/span><\/strong><\/code><\/p>\n<p><code>C:\\Projects&gt;<strong><span style=\"color: #000000;\">cd MyProject<\/span><\/strong><\/code><\/p>\n<p><code>C:\\Projects\\MyProject&gt;<strong><span style=\"color: #000000;\">git remote add personalci C:\\Projects\\MyProjectPersonalCI.git<\/span><\/strong><\/code><\/p>\n<p><code>C:\\Projects\\MyProject&gt;<strong><span style=\"color: #000000;\">git remote<\/span><\/strong><\/code><\/p>\n<p><code>origin<\/code><\/p>\n<p><code>personalci<\/code><\/p><\/blockquote>\n<p>All we have to do now is push our changes to the personalci remote and they will be visible to the CI server. Let\u00e2\u20ac\u2122s do that now (if there is any code in your project to commit).<\/p>\n<blockquote><p><code>C:\\Projects\\MyProject&gt;<strong><span style=\"color: #000000;\">git push personalci master<\/span><\/strong><\/code><\/p>\n<p><code>Counting objects: 899, done.<\/code><\/p>\n<p><code>Delta compression using up to 2 threads.<\/code><\/p>\n<p><code>Compressing objects: 100% (554\/554), done.<\/code><\/p>\n<p><code>Writing objects: 100% (899\/899), 13.93 MiB | 3.15 MiB\/s, done.<\/code><\/p>\n<p><code>Total 899 (delta 422), reused 691 (delta 332)<\/code><\/p>\n<p><code>To C:\\Projects\\MyProjectPersonalCI.git<\/code><\/p>\n<p><code>* [new branch] master \u00e2\u20ac\u201c&gt; master<\/code><\/p><\/blockquote>\n<p><em>Your output may differ depending on how many files you have uncommitted in your project folde. I am adding this to an existing project of mine, so there are quite a few files.<\/em><\/p>\n<p>The command <code><strong>git push personalci master<\/strong><\/code> is telling Git to push the changes from the master branch on my local repository to the master branch on the personalci remote repository. The remote master branch was automatically created for us since it didn\u00e2\u20ac\u2122t already exist.<\/p>\n<p><em>If you are having trouble understanding what Git is doing here, I encourage you to read the <\/em><a href=\"http:\/\/git-scm.com\/documentation\" target=\"_blank\"><em>documentation<\/em><\/a><em>. I don\u00e2\u20ac\u2122t want to dive too deep into Git since it\u00e2\u20ac\u2122s beyond the scope of this article.<\/em><\/p>\n<p>Now we can push our changes up to the CI Server. Lets automate it.<\/p>\n<h2>Creating the Batch File<\/h2>\n<p>This batch file will do three things:<\/p>\n<ol>\n<li>Add any untracked files.<\/li>\n<li>Commit all changes with a custom commit message.<\/li>\n<li>Push the changes to the personalci remote repository.<\/li>\n<\/ol>\n<p>Create a file in the root of your git repository called \u00e2\u20ac\u0153CommitAndPushToPersonalCI.bat\u00e2\u20ac\u009d. Yeah, I know\u00e2\u20ac\u00a6I\u00e2\u20ac\u2122m a sucker for long descriptive names.<\/p>\n<pre class=\"vb\">@REM CommitAndPushToPersonalCI.bat\r\n@REM This script adds any untracked files and commits them and any changes to git.\r\n@REM It then pushes the git repository changes up to the \"personalci\" remote repository.\r\n@REM From there, a CI Server should pick up and run the build.\r\n\r\n@ECHO on\r\n@ECHO Auto-committing to Git Repository and push to PersonalCI after Successful Build.\r\n\r\n@REM Add files that are outstanding to the local git repository.\r\ncall git add .\r\n@if errorlevel 1 goto :error\r\n\r\n@REM Commit all files to the repository with an autogenerated commit message.\r\ncall git commit -a -m \"Auto-commit from successful build on %COMPUTERNAME% by %USERNAME% at %TIME% on %DATE%\"\r\n@if errorlevel 1 goto :error\r\n\r\n@REM Push to the personalci remote repository.\r\ncall git push personalci master\r\n@if errorlevel 1 goto :error\r\n\r\n@ECHO.\r\n@ECHO SUCCESS: Pushed to Personal CI\r\n@goto :exit\r\n\r\n:error\r\n@ECHO.\r\n@ECHO ERROR! -- ErrorLevel: %errorLevel%\r\n\r\n:exit<\/pre>\n<p>The code batch file is simple and should pretty much explain itself.<\/p>\n<p>Run the batch file and you should get output similar to&#8211;but not exactly the same as the following:<\/p>\n<p><a href=\"https:\/\/www.chrisedwards.dreamhosters.com\/blog\/wp-content\/uploads\/2010\/06\/image3.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border-width: 0px;\" title=\"image\" src=\"https:\/\/www.chrisedwards.dreamhosters.com\/blog\/wp-content\/uploads\/2010\/06\/image_thumb3.png\" border=\"0\" alt=\"image\" width=\"704\" height=\"191\" \/><\/a><\/p>\n<p>We have everything ready, all we need now is to get Visual Studio to fire it off when we build.<\/p>\n<p><a href=\"https:\/\/www.chrisedwards.dreamhosters.com\/blog\/2010\/06\/21\/extreme-ci-part-3-the-visual-studio-macro\/\" target=\"_blank\">Extreme CI Part 3: The Visual Studio Macro<\/a><\/p>\n<p>-Chris<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How I run a personal CI build every time I build my code in Visual Studio. Summary This week we setup Git so it commits your changes and pushes them up to the personal CI server. We\u00e2\u20ac\u2122ll also create a batch file to automate this process. In part 3 we\u00e2\u20ac\u2122ll create the Visual Studio macro [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,4,32,8,33],"tags":[79,76,45,71,83],"class_list":["post-183","post","type-post","status-publish","format-standard","hentry","category-net","category-agile","category-continuous-integration","category-testing","category-visual-studio","tag-net","tag-agile","tag-continuousintegration","tag-testing","tag-visual-studio"],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/posts\/183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/comments?post=183"}],"version-history":[{"count":5,"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/posts\/183\/revisions"}],"predecessor-version":[{"id":216,"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/posts\/183\/revisions\/216"}],"wp:attachment":[{"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/media?parent=183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/categories?post=183"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/architester.com\/blog\/wp-json\/wp\/v2\/tags?post=183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}