Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /output props #534

Closed
wants to merge 7 commits into from
Closed

Conversation

serra
Copy link
Contributor

@serra serra commented Jul 25, 2015

This allows for easy integration with Jenkins CI server.

Any feedback is welcome.

I think I understood how to write most tests, but I did not know how to test the actual output of gitversion.exe.

Hope this helps!

@serra
Copy link
Contributor Author

serra commented Jul 25, 2015

I'm on the failing test ...

@JakeGinnivan
Copy link
Contributor

It might be good to instead have an argument which writes out the file (it should also support appending).

I assume Jenkins captures build output, so I like to rule /output console so I can debug things if/when it goes wrong.

@serra
Copy link
Contributor Author

serra commented Jul 26, 2015

It might be good to instead have an argument which writes out the file (it should also support appending).

This is what I would use in a Windows batch command:

# overwrite:
gitversion /output props > gitversion.properties
# append:
gitversion /output props >> gitversion.properties

I like that gitversion allows us to use its output this way, no need for additional functionality in GitVersion IMO.

@JakeGinnivan what do wou mean by

I assume Jenkins captures build output, so I like to rule /output console so I can debug things if/when it goes wrong.

@JakeGinnivan
Copy link
Contributor

If I have a look at a GitVersion build log, I get

.\build\NuGetCommandLineBuild\tools\GitVersion.exe /l console /output buildserver /updateAssemblyInfo
INFO [07/26/15 14:44:09:31] Working directory: C:\projects\gitversion
INFO [07/26/15 14:44:09:34] Applicable build agent found: 'AppVeyor'.
INFO [07/26/15 14:44:09:37] One remote found (origin -> 'https://github.com/GitTools/GitVersion.git').
INFO [07/26/15 14:44:09:37] Fetching from remote 'origin' using the following refspecs: +refs/heads/*:refs/remotes/origin/*.
INFO [07/26/15 14:44:09:74] Creating local branch from remote tracking 'refs/remotes/origin/gh-pages'.
INFO [07/26/15 14:44:09:77] Skipping local branch creation since it already exists 'refs/remotes/origin/master'.
INFO [07/26/15 14:44:09:77] Creating local branch from remote tracking 'refs/remotes/origin/updateTask'.
INFO [07/26/15 14:44:09:77] HEAD is detached and points at commit 'f43784426f0ac34217b03be4c41b020f3a21a8f3'.
INFO [07/26/15 14:44:09:79] No local branch pointing at the commit 'f43784426f0ac34217b03be4c41b020f3a21a8f3'. Fake branch needs to be created.
INFO [07/26/15 14:44:09:90] Found remote tip 'refs/pull/537/merge' pointing at the commit 'f43784426f0ac34217b03be4c41b020f3a21a8f3'.
INFO [07/26/15 14:44:09:90] Creating fake local branch 'refs/heads/pull/537/merge'.
INFO [07/26/15 14:44:09:90] Checking local branch 'refs/heads/pull/537/merge' out.
INFO [07/26/15 14:44:09:96] Project root is: C:\projects\gitversion
INFO [07/26/15 14:44:10:07] Using latest commit on specified branch
INFO [07/26/15 14:44:10:07] Begin: Attempting to inherit branch configuration from parent branch
  INFO [07/26/15 14:44:10:08] HEAD is merge commit, this is likely a pull request using master as base
  INFO [07/26/15 14:44:10:08] Begin: Finding branch source
  INFO [07/26/15 14:44:10:16] End: Finding branch source (Took: 78.13ms)
  INFO [07/26/15 14:44:10:16] Found possible parent branches: master
INFO [07/26/15 14:44:10:16] End: Attempting to inherit branch configuration from parent branch (Took: 93.75ms)
INFO [07/26/15 14:44:10:18] Running against branch: pull/537/merge (f43784426f0ac34217b03be4c41b020f3a21a8f3)
INFO [07/26/15 14:44:10:18] Begin: Calculating base versions
  INFO [07/26/15 14:44:10:23] Fallback base version: 0.1.0 with commit count source e863c4daa20495331731b5796f0be6cacef710cb
  INFO [07/26/15 14:44:10:24] NextVersion in GitVersionConfig.yaml: 3.0.0 with commit count source External Source
  INFO [07/26/15 14:44:10:30] Git tag 'v3.0.0-beta.4': 3.0.0-beta.4 with commit count source bec5eb5c626a93d97b5673deda6ec50d1191e267
  INFO [07/26/15 14:44:10:30] Git tag '3.0.0-Beta3': 3.0.0-Beta.3 with commit count source 24fa6b525655eddf64272b11f43ac27da34ab15e
  INFO [07/26/15 14:44:10:30] Git tag '3.0.0-Beta2': 3.0.0-Beta.2 with commit count source fe1063fbb5fada6555c4ade59055f10a910e851f
  INFO [07/26/15 14:44:10:30] Git tag '3.0.0-Beta1': 3.0.0-Beta.1 with commit count source f7b096f4585709be43b5d13a2de9f3cd44b7e97e
  INFO [07/26/15 14:44:10:30] Git tag '2.0.1': 2.0.1 with commit count source 16e28fa26c71dc3c20799969b8fbd2737eac432e
  INFO [07/26/15 14:44:10:30] Git tag '2.0.0': 2.0.0 with commit count source 50d6f03171a3aae8487bf88ccfdd7fd273546b99
  INFO [07/26/15 14:44:10:30] Git tag '1.3.3': 1.3.3 with commit count source 963a0243359cb9d7287be2c4440542adc432db65
  INFO [07/26/15 14:44:10:30] Git tag '1.3.2': 1.3.2 with commit count source 332480f2a8266ba232e20072b627ea02db21fdcc
  INFO [07/26/15 14:44:10:30] Git tag '1.3.1': 1.3.1 with commit count source 875479602c908f4a4d2a473d6cf72b4a2bf644e6
  INFO [07/26/15 14:44:10:30] Git tag '1.2.1': 1.2.1 with commit count source dff80ea8efcc0482a0708cbfd6d487230f59a383
  INFO [07/26/15 14:44:10:30] Git tag '1.2.0': 1.2.0 with commit count source 9b1eafbf9499c486ce1a3b9851695c5581e4be44
  INFO [07/26/15 14:44:10:30] Git tag '1.1.1': 1.1.1 with commit count source a4b40aaec5a7bc1f9bb668fed5c4879dc36f8099
  INFO [07/26/15 14:44:10:30] Git tag '1.1.0': 1.1.0 with commit count source a813c97828a543b4fa2a8b43f52646bb52497ed7
  INFO [07/26/15 14:44:10:30] Git tag '1.0.0': 1.0.0 with commit count source 0d72bbfad34be683e8131ed7ad365e7a99302ae3
  INFO [07/26/15 14:44:10:40] Merge message 'Merge remote-tracking branch 'upstream/master' into release/3.0.0': 3.0.0 with commit count source bec5eb5c626a93d97b5673deda6ec50d1191e267
  INFO [07/26/15 14:44:10:40] Merge message 'Merge branch 'master' into release/3.0.0': 3.0.0 with commit count source 5ee62f0ed545fab4d3fb8674f8bd67b622bcc014
  INFO [07/26/15 14:44:10:40] Merge message 'Merge remote-tracking branch 'upstream/master' into release/3.0.0': 3.0.0 with commit count source d796782de498d3e29330b74a3881fe6436a2941a
  INFO [07/26/15 14:44:10:40] Merge message 'Merge pull request #467 from Sacrelicious/release/3.0.0

Filter out merge messages that look like versions but aren't': 3.0.0 with commit count source fe26bb1f0835080749923f4745128ab43047f4fa
  INFO [07/26/15 14:44:10:40] Merge message 'Merge branch 'release/3.0.0' into feature/improved-exception-handling': 3.0.0 with commit count source abc46c48c4ebeccd32431470a722363619603e0d
  INFO [07/26/15 14:44:10:40] Merge message 'Merge pull request #364 from ParticularLabs/release/3.0.0

Release/3.0.0': 3.0.0 with commit count source 049624a5321a18303d18686493dc5581bd6e529a
  INFO [07/26/15 14:44:10:40] Merge message 'Merge pull request #377 from anobleperson/release/3.0.0

Fixes #375 - Made known merge branch version number extraction case insensitive': 3.0.0 with commit count source f18f1895456687305c113e938f9aee8022a212bb
  INFO [07/26/15 14:44:10:40] Merge message 'Merge branch 'GeertvanHorrik-pr/NextVersionForDynamicRepositories' into release/3.0.0': 3.0.0 with commit count source b7e2826c65c3ee66e6807f96494bf43b1022b871
  INFO [07/26/15 14:44:10:40] Merge message 'Merge remote-tracking branch 'upstream/master' into release/3.0.0': 3.0.0 with commit count source cc7441ee7c9d4ec50ed83d100a519a21fdd0a3af
  INFO [07/26/15 14:44:10:40] Merge message 'Merge pull request #165 from Particular/release-1.0.0

Release 1.0.0': 1.0.0 with commit count source 102697b7d0bc5cae13fa60f435aa4931dffc62ff
  INFO [07/26/15 14:44:10:41] Found multiple base versions which will produce the same SemVer (3.0.0), taking oldest source for commit counting (Merge message 'Merge branch 'GeertvanHorrik-pr/NextVersionForDynamicRepositories' in
to release/3.0.0')
  INFO [07/26/15 14:44:10:41] Base version used: Merge message 'Merge remote-tracking branch 'upstream/master' into release/3.0.0': 3.0.0 with commit count source b7e2826c65c3ee66e6807f96494bf43b1022b871
INFO [07/26/15 14:44:10:41] End: Calculating base versions (Took: 234.38ms)
INFO [07/26/15 14:44:10:41] Skipping version increment
INFO [07/26/15 14:44:10:43] 303 commits found between b7e2826c65c3ee66e6807f96494bf43b1022b871 and f43784426f0ac34217b03be4c41b020f3a21a8f3
INFO [07/26/15 14:44:10:44] Applicable build agent found: 'AppVeyor'.
Executing GenerateSetVersionMessage for 'AppVeyor'.
Set AppVeyor build number to '3.0.0-PullRequest.537+303 (Build 138)'.
Executing GenerateBuildLogOutput for 'AppVeyor'.
Adding Environment Variable. name='GitVersion_Major' value='3']
Adding Environment Variable. name='GitVersion_Minor' value='0']
Adding Environment Variable. name='GitVersion_Patch' value='0']
Adding Environment Variable. name='GitVersion_PreReleaseTag' value='PullRequest.537']
Adding Environment Variable. name='GitVersion_PreReleaseTagWithDash' value='-PullRequest.537']
Adding Environment Variable. name='GitVersion_BuildMetaData' value='303']
Adding Environment Variable. name='GitVersion_FullBuildMetaData' value='303.Branch.pull/537/merge.Sha.f43784426f0ac34217b03be4c41b020f3a21a8f3']
Adding Environment Variable. name='GitVersion_MajorMinorPatch' value='3.0.0']
Adding Environment Variable. name='GitVersion_SemVer' value='3.0.0-PullRequest.537']
Adding Environment Variable. name='GitVersion_LegacySemVer' value='3.0.0-PullRequest537']
Adding Environment Variable. name='GitVersion_LegacySemVerPadded' value='3.0.0-PullRequest0537']
Adding Environment Variable. name='GitVersion_AssemblySemVer' value='3.0.0.0']
Adding Environment Variable. name='GitVersion_FullSemVer' value='3.0.0-PullRequest.537+303']
Adding Environment Variable. name='GitVersion_InformationalVersion' value='3.0.0-PullRequest.537+303.Branch.pull/537/merge.Sha.f43784426f0ac34217b03be4c41b020f3a21a8f3']
Adding Environment Variable. name='GitVersion_BranchName' value='pull/537/merge']
Adding Environment Variable. name='GitVersion_Sha' value='f43784426f0ac34217b03be4c41b020f3a21a8f3']
Adding Environment Variable. name='GitVersion_NuGetVersionV2' value='3.0.0-pullrequest0537']
Adding Environment Variable. name='GitVersion_NuGetVersion' value='3.0.0-pullrequest0537']
Adding Environment Variable. name='GitVersion_CommitDate' value='2015-07-26']
Updating assembly info files

So the log messages go to the console. I then use the environmental variables later in the build. I find the gitversion logs handy, which is why it might be good to allow the output to be directed to a file and the log to go to the console?

@serra
Copy link
Contributor Author

serra commented Jul 27, 2015

Ah, I see what you're at. How is logging configured for GitVersion? Is it a --verbose switch?

If I do gitversion /output json I would expect NOT to get these log message directed to the console. Am I correct?

@serra
Copy link
Contributor Author

serra commented Jul 27, 2015

E.g. in a power shell prompt I do $gfv = $(gitversion) | ConvertFrom-Json which gives me PS object with all gitversion variables, so that I can do e.g. $gfv.SemVer. This would fail if the log messages get written to the console output.

@serra
Copy link
Contributor Author

serra commented Jul 28, 2015

@JakeGinnivan thanks for the link.

I do not fundamentally object writing this to a file directly (and it would also meet my personal needs for better Jenkins integration), but I still feel writing it to the console (both json and props) is more flexible, allows for good integration with other tools (I really don't understand anobleperson's problems mentioned in #404) and has really small code-footprint.

But if you guys feel like writing to a file is better let me know and I'll be happy to implement.

@JakeGinnivan
Copy link
Contributor

If a build fails due to gitversion, how does the user see the logs? Or if gitversion calculates the version wrong?

Unless you setup the gitversion logs to a file which is automatically picked up as an artifact not sure what we can do?

The issue is that you cannot log the result and also the log to the build output at the same time, I think we dump the log to the console when it fails but not sure that is enough/ideal. This is the idea of plugins/service messages. We can log and give the build server the result.

Currently there are two command line variables which control this, /log and /output, I think both should be able to go to console and also a file, just not both going to console at the same time.

@serra
Copy link
Contributor Author

serra commented Jul 28, 2015

OK, but doesn't that mean that gitversion /output json is fundamentally broken because of this? I for one assumed I would only get the json output written to stdout, not the log messages.

I'll let this sink in for a moment and come up with a proposal. I understand your thoughts a lot better now, thanks.

@serra
Copy link
Contributor Author

serra commented Jul 28, 2015

Of course, I might be the only using gitversion this way ... one must never rule that out 😄

@serra
Copy link
Contributor Author

serra commented Jul 28, 2015

Note to self: the console output is used for several purposes :

  1. writing out the result (in json format)
  2. writing out log messages in case of gitversion /l console
  3. writing out "service messages" in case of /output buildserver
  4. writing out config information in case of gitversion init
  5. some other locations; Console.WriteLine has 10 usage in exe project

So in some cases we might get additional text written to the console, making it unreliable to use gitversion stdout for further processing:

  1. when /l console argument is used
  2. -when /l [path to log file] is used- this outputs to file and not to stdout
  3. when /output buildserver is used, which might output to the console, depending on the used implementation

So:

  • WHEN NOT using /l it is safe to use /output [json|props] and pipe the console output for further processing.
  • WHEN using /l it is not safe to pipe console output for further processing. In this case it might be useful to be able to specify a filename where output (in either json or props format) should be written to.

@serra serra mentioned this pull request Jul 28, 2015
10 tasks
@JakeGinnivan
Copy link
Contributor

/l mylog.log will write log to a file. console is a special value.

This is one of the things I would like to try to figure out and fix in #428 for v4..

@serra
Copy link
Contributor Author

serra commented Jul 29, 2015

OK. Although this was an interesting exercise, this is not the way to go.

I assumed that using the output to stdout for further processing was the way to go, but this discussion revealed to me that this is a questionable assumption.

I can meet my need by implementing this in a /buildserver with Jenkins detection. This will work exactly the same way as described here. But this will be implemented in Jenkins : BuildServerBase that outputs a gitversion.properties file that can be picked up by the EnvInject. I hope to open a PR for this Jenkins support soon (next couple of days).

@serra serra closed this Jul 29, 2015
@JakeGinnivan
Copy link
Contributor

👍 awesome, thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants