You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Azure DevOps Pipeline (the web based build system) you can call GitVersion
13
-
either using the Command Line build step or install an extension / custom build
14
-
step. The custom build step requires a one-time setup to import the GitVersion
15
-
task into your TFS or Azure DevOps Pipeline instance.
10
+
For Azure DevOps Services or Azure DevOps Server you can install the [GitTools Bundle](https://marketplace.visualstudio.com/items?itemName=gittools.gittools).
16
11
17
12
:::{.alert .alert-danger}
18
13
**Important**
@@ -22,160 +17,4 @@ without it, Azure DevOps Pipelines will perform a shallow clone, which will caus
22
17
See [the Azure DevOps documentation](https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/steps-checkout?view=azure-pipelines#shallow-fetch) for more information.
23
18
:::
24
19
25
-
## Executing GitVersion
26
-
27
-
### Using GitVersion with the MSBuild Task NuGet Package
28
-
29
-
1. Add the [GitVersionTask](https://www.nuget.org/packages/GitVersionTask/)
30
-
NuGet package to your projects.
31
-
32
-
See [MSBuild Task](/docs/usage/msbuild) for further instructions how to use
33
-
the MS Build Task.
34
-
35
-
### Using GitVersion with the Command Line build step
36
-
37
-
1. Make sure to have GitVersion.exe under version control. There exists also a
38
-
[Chocolatey package](https://chocolatey.org/packages/GitVersion.Portable) for
39
-
installing GitVersion.exe on build agents.
40
-
2. Add a Command Line build step to your build definition. You'll probably want
41
-
to drag the task to be at or near the top to ensure it executes before your
42
-
other build steps.
43
-
3. Set the Tool parameter to `<pathToGitVersion>\GitVersion.exe`.
44
-
4. Set the Arguments parameter to `/output buildserver /nofetch`.
45
-
5. If you want the GitVersionTask to update AssemblyInfo files add
46
-
`updateAssemblyInfo true` to the Arguments parameter.
47
-
6. If you want to update the build number you need to send a
##### Manually installing/updating the custom build step
64
-
65
-
If you run TFS 2015 RTM or Update 1 or don't want to install the GitVersion
66
-
extension you can install the build task manually:
67
-
68
-
1. Install the `tfx` command line tool as shown [here](https://github.com/microsoft/tfs-cli/blob/master/README.md#setup).
69
-
2. For TFS 2015 On-Prem configure Basic Authentication in TFS as shown [here](https://github.com/microsoft/tfs-cli/blob/master/docs/configureBasicAuth.md).
70
-
3. Download the GitVersion TFS build task from the latest release on the
71
-
[GitVersion releases page](https://github.com/GitTools/GitVersion/releases) and
72
-
unzip.
73
-
4. Run `tfx login` as shown [here](https://github.com/microsoft/tfs-cli/blob/master/README.md#login).
74
-
5. From the directory outside of where you unzipped the task, run
75
-
`tfx build tasks upload --task-path .\GitVersionVsixTask --overwrite` where
76
-
GitVersionVsixTask is the directory containing the files.
77
-
6. It should successfully install.
78
-
79
-
#### Using the GitVersion custom build step
80
-
81
-
From a TFS build definition, select "Add a Step" and then in the Build category,
82
-
choose GitVersion and click Add. You'll probably want to drag the task to be at
83
-
or near the top to ensure it executes before your other build steps.
84
-
85
-
If you want the GitVersionTask to update AssemblyInfo files, check the box in
86
-
the task configuration. For advanced usage, you can pass additional options to
87
-
the GitVersion exe in the Additional arguments section.
88
-
89
-
The Azure DevOps Pipeline build step can update your build number with
90
-
GitVersion variables. See below for details.
91
-
92
-
#### Using Pipelines yaml
93
-
94
-
Add the following yaml task and variable to your `azure-pipelines.yml` file:
95
-
96
-
```yml
97
-
variables:
98
-
GitVersion.SemVer: ''
99
-
100
-
steps:
101
-
- task: UseGitVersion@5
102
-
displayName: gitversion
103
-
inputs:
104
-
versionSpec: '5.x'
105
-
updateAssemblyInfo: true
106
-
```
107
-
108
-
You can now use the `GitVersion.SemVer` environment variable in any subsequent
109
-
tasks to refer to the semantic version number for your build. For example, you
110
-
can build your dotnet core application with a semantic version number like so:
111
-
112
-
```yml
113
-
- task: DotNetCoreCLI@2
114
-
displayName: Build
115
-
inputs:
116
-
command: build
117
-
projects: '$(solution)'
118
-
configuration: '$(buildConfiguration)'
119
-
versioningScheme: byEnvVar
120
-
versionEnvVar: 'GitVersion.SemVer'
121
-
122
-
```
123
-
124
-
## Running inside TFS
125
-
126
-
### Using the GitVersion Variables
127
-
128
-
GitVersion passes variables in the form of `GitVersion.*` (Eg:
129
-
`GitVersion.Major`) to TFS Build and also writes `GITVERSION.*`
130
-
(Eg: `GITVERSION.MAJOR`) environment variables that are available for any
131
-
subsequent build step.
132
-
133
-
To use these variables you can just refer to them using the standard variable
134
-
syntax. For instance `$(GitVersion.NuGetVersion)` in your nuget pack task to set
135
-
the version number. Since update 1 there are no known limitations.
136
-
137
-
See [Variables](/docs/reference/variables) for an overview of available variables.
138
-
139
-
#### Using GitVersion variables in build name
140
-
141
-
To use GitVersion's variables in the build name, just add them in the form
142
-
`$(GITVERSION_FullSemVer)`into the Build definition's build number string. Then
143
-
just ensure GitVersion is called with `/output buildserver` and it will replace
144
-
those variables with the calculated version. The TFS GitVersion Build Step
145
-
(above) handles this too, so if you're already using that, there's nothing extra
146
-
to configure.
147
-
148
-
If GitVersion does not find any substitutions it will just default to using `FullSemVer`
149
-
150
-
:::{.alert .alert-danger}
151
-
**Important**
152
-
153
-
If you currently use `$(rev:.r)` in your build number, that won't
154
-
work correctly if you
155
-
use GitVersion variables as well due to the delayed expansion of the GitVersion
156
-
vars. Instead, you might be able to use `$(GitVersion_BuildMetaData)` to achieve
157
-
a similar result. See [Variables](/docs/reference/variables) for more info on the
158
-
variables.
159
-
:::
160
-
161
-
#### Known limitations
162
-
163
-
* If you are using on premises TFS, make sure you are using at least
164
-
**TFS 2015 Update 1**, otherwise a few things will not work.
165
-
* Installing the extension on an on premise TFS requires at least TFS 2015
166
-
Update 2.
167
-
* You need to make sure that all tags are fetched for the Git repository,
168
-
otherwise you may end with wrong versions (e.g. `FullSemVer` like `1.2.0+5`
169
-
instead of `1.2.0` for tagged releases) Just checking the `Clean Repository`
170
-
check box in the build definition settings might not be enough since this will
171
-
run a `git clean -fdx/reset --hard` without fetching all tags later. You can
172
-
force deletion of the whole folder and a re-clone containing all tags by
173
-
settings the variable `Build.Clean` to `all`. This will take more time during
174
-
build but makes sure that all tags are fetched. In the future it is planned to
175
-
allow using `git.exe` instead of current `libgit2sharp` for syncing the repos
176
-
which might allow other possibilities to solve this issue. For details see this
0 commit comments