Here is a short tutorial (with extra long title!) how to improve the JetBrains TeamCity Build Server for CI (Continuos Integration).
This is what wiill do to improve TeamCity 7:
- Change the Build version number to include Git short hash (7 chars) as Revison e.g. 1.0.1.53e7986.
- Upload file to Amazon S3.
- Send email via Gmail with:
- Latest downloadable link of release from Amazon S3.
- Developer commit message details.
Note:
This is not blog post how to set up TeamCity, this is usually really straight forward thing to do. So in this blog post I assume that there is TeamCity project and at least one Build Configuration already created!
Setting Git Short Hash as Revision of TeamCity Build Number
- In TeamCity go to desired named ”Build Configuration” in our case ”aeon”.
- Click somewhere on right side on Edit Configuration Settings to enter aeon Configuration Steps.
- In (1) General Settings set Build format number to something like 1.0.{0} and Save.
- In (3) Build Steps click Add build step choose Powershell in listbox.
- Set Name if you want like ”Get Build Number with short Git Hash”.
- For Script choose ”Source code” from drop down box.
- In Script Source add following Powershell code and click Save:
1 2 3 4 |
|
- Script execution mode should not matter, mine is “Execute .ps1 script…”.
- After save make sure that this Build Step is first!!!!
- Use Reorder build steps link, if you have existing build setps.
Note:
When build starts by Agent, it will be 1.0.1 and at the end it will change to 1.0.1.53e7986!
Shell version (Linux or Mac)
- All same as Powershell until (3) Build Steps.
- In (3) Build Steps click Add build step choose Command line in listbox.
- In Custom Script add following shell script and click Save:
1 2 3 4 |
|
Note:
I didn’t test shell version, it should work, but maybe some tweaks are necessary!
Powershell script for sending file to Amazon S3 and sending email via Gmail
- Download and install AWS Tools for Windows Powershell.
- With this SDK is really easy to upload file to Amazon S3.
- Amazon S3 account is needed and also Access Key and Secret Key.
- Assumes that Amazon S3 bucket name is ”aeon” and region is ”eu-west-1”.
- This will produce https://s3-eu-west-1.amazonaws.com/aeon/
” . - The script is lousy written, it should be better, especially when it is needed to be reused for multiple Builded apps.
- The thing needed to be entered will be inside “<something-to-do>”.
- In my case the uploaded file is “.exe” file so it is harcoded in Amazon S3 URL.
- Make sure that file name is not really crazy and there are no spaces in it (it is always easier this way)!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
- Save this script to <whatever-you-want-to-call-it>.ps1.
- This Powershell script can be added to TeamCity as a final Build Step.
- In (3) Build Steps click Add build step choose Powershell in listbox.
- For Script choose File from drop down box.
- For Script File add absolute path to saved Powershell script saved as ps1.
Note:
Sorry, no Linux or Mac shell version of this script.
Conclusion
Having short Git hash for a Revision in your versioning is very helpful and seven chars are mostly always enough to uniquely identify this release build with commit in your Git repository.
The amazon S3 upload + send email with developer commit deatails is not state of art Powershell script, it is very buggy and not that much flexible, but it can help a lot in communication with QA (or outside beta testers) and having release build version binary, right after Developer commit!