Skip to content

Instantly share code, notes, and snippets.

@mwwhited
Created November 20, 2020 12:38
Show Gist options
  • Save mwwhited/0582eb083730bbf0b37386e665040687 to your computer and use it in GitHub Desktop.
Save mwwhited/0582eb083730bbf0b37386e665040687 to your computer and use it in GitHub Desktop.
Configure and use GitVersion

Using GitVersion

Summary

Gitversion is a tool to generate version numbers based on your git repository commit history.

Configure

To customize GitVersion create a GitVersion.yml file at the root of your repository. Use this file to configure your repository. For framework libraries it is suggested to use Continuous Deliver for applications such as native tools, uis and website use Mainline Development

Install and Use locally

GitVersion is a dotnet tool. This tool allows you you see and test what GitVersion will calculate for your CI/CD pipeline.

Install Globally

dotnet tool install --global gitversion.tool

Display Current Version Options

From within a directory for a git repository

dotnet gitversion

Show current configuration

dotnet gitverion --showconfig

Use in CI/CD Pipelines

Local Batch Files

git fetch --prune
FOR /F "tokens=* USEBACKQ" %%g IN (`dotnet gitversion /output json /showvariable FullSemVer`) DO (SET BUILD_VERSION=%%g)
ECHO Building Version=  "%BUILD_VERSION%"

Local Linux Scripts

git fetch --prune
buildVersion=`dotnet gitversion /output json /showvariable FullSemVer`
echo GitVersion= $buildVersion

Azure Devops

Add these to under the steps of the job you want to version.

- task: gitversion/setup@0
  displayName: Install GitVersion
  inputs:
    versionSpec: '5.1.3'
- task: gitversion/execute@0
  displayName: Use GitVersion
  inputs:
    useConfigFile: true
    configFilePath: 'GitVersion.yml'
- script: |
          echo FullSemVer=$(fullSemVer)
          echo ##vso[build.updatebuildnumber]$(fullSemVer)
          echo ##vso[task.setvariable variable=fullSemVer]$(fullSemVer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment