I am building my asp.net core project in Gitlab CI and Docker using Gitversion as an MSBuild task. I can't seem to find the correct environment variable to access the version within the Gitlab pipeline. Any help would be much appreciated :)
This should be tagged as a question but I can't quite figure out how to do that, sorry :(
The variables should be available as GitVersion_<VariableName>. For a list of the specific variables exposed by GitVersion, please refer to the documentation.
Thanks for getting back! Your help is appreciated :)

I tried that previously but it didn't seem to find any values there. I would expect the echo to output a variable.
Maybe my Dockerfile is wrong?
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
# Copy project files
WORKDIR /source
COPY ["MiniAppApiServer/MiniAppApiServer.csproj", "./MiniAppApiServer/"]
# Restore
WORKDIR /source
RUN dotnet restore "./MiniAppApiServer/MiniAppApiServer.csproj"
#RUN gitversion /output buildserver
# Copy all source code
COPY . .
# Publish
WORKDIR /source
RUN dotnet publish -c Debug -o /publish
# Runtime
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /publish
COPY --from=build-env /publish .
ENTRYPOINT ["dotnet", "MiniAppApiServer.dll"]
Running gitversion /output buildserver inside a Docker container is not going to expose anything to the outside. You need to read variables from the container and then expose them to the outside yourself if GitVersion is being executed within a container.
I'm having the same problem in GitLab CI. I don't see how the buildserver output is supposed to work on Linux, because child processes can't modify the parent's environment variables.
The automatic build server detection also doesn't seem to be overridable with /output json, which makes this tool a bit annoying to use on Linux. Are there any plans to solve this?
Adding GIT_DEPTH: 0 as a variable to the CI job fixed the issue for me, seems like it couldn't resolve the version otherwise.