gitdockerazure-pipelines

NerdBank GitVersioning docker container: unsupported repository version 1. Only versions up to 0 are supported


I am trying to make an AWS EC2 instance a build machine for azure devops, In my pipeline I am trying to use a nerdbank gitversioning docker container to get the build version. The start of the pipeline looks like:

steps:
- checkout: self
  fetchDepth: 0

- script: |
    docker pull andrewlock/nerdbank-gitversioning:latest
  displayName: 'Pull Docker Image'

- script: |
    VERSION=$(docker run --rm -v $(pwd):$(pwd) -w $(pwd) andrewlock/nerdbank-gitversioning:latest get-version | grep -oP '(^Version:)\K.*' | xargs)
    echo "Version found: $VERSION"
    echo "##vso[task.setvariable variable=VERSION]$VERSION"  # Sets VERSION as a variable for later steps
  displayName: 'Get version from Docker'

However when I run the pipeline on the EC2 instance, I get the error:

Unhandled Exception: LibGit2Sharp.LibGit2SharpException: unsupported repository version 1. Only versions up to 0 are supported.
   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
   at LibGit2Sharp.Core.Proxy.git_repository_open(String path)
   at LibGit2Sharp.Repository..ctor(String path, RepositoryOptions options, RepositoryRequiredParameter requiredParameter)
   at Nerdbank.GitVersioning.GitExtensions.OpenGitRepo(String pathUnderGitRepo)
   at Nerdbank.GitVersioning.Tool.Program.OnGetVersionCommand(String projectPath, String format, String versionOrRef) in D:\a\1\s\src\nbgv\Program.cs:line 236
   at Nerdbank.GitVersioning.Tool.Program.Main(String[] args) in D:\a\1\s\src\nbgv\Program.cs:line 110
Version not found! Failing the pipeline.

When I run the build on my own laptop as a build agent, the pipeline runs fine.

I've tried setting the git config to use repository version 0 in the cloud init startup script:

su ubuntu -c "git config --global core.repositoryFormatVersion 0"
echo "[url \"https://\"]" >> /home/ubuntu/.gitconfig
echo "  insteadOf = git://" >> /home/ubuntu/.gitconfig
echo "[core]" >> /home/ubuntu/.gitconfig
echo "  repositoryFormatVersion = 0" >> /home/ubuntu/.gitconfig

The git config also says it is version 0:

cat .\.git\config                      
[core]
        repositoryformatversion = 0

However it is still failing. I am not sure why it works on my laptop, but not on AWS. Why is this happening?

For reference, my full cloud init script is:

#!/bin/bash

export VSTS_AGENT_INPUT_URL=${url}
export VSTS_AGENT_INPUT_AUTH=pat
export VSTS_AGENT_INPUT_TOKEN=${token}
export VSTS_AGENT_INPUT_POOL=${pool}

echo "export VSTS_AGENT_INPUT_URL=${url}" >> /home/ubuntu/.bashrc
echo "export VSTS_AGENT_INPUT_AUTH=pat" >> /home/ubuntu/.bashrc
echo "export VSTS_AGENT_INPUT_TOKEN=${token}" >> /home/ubuntu/.bashrc
echo "export VSTS_AGENT_INPUT_POOL=${pool}" >> /home/ubuntu/.bashrc

cd /home/ubuntu
usermod -aG docker ubuntu

wget https://vstsagentpackage.azureedge.net/agent/4.248.0/vsts-agent-linux-x64-4.248.0.tar.gz
mkdir myagent && cd myagent
tar zxvf ../vsts-agent-linux-x64-4.248.0.tar.gz
./bin/installdependencies.sh

chown -R ubuntu:ubuntu .
su ubuntu -c './config.sh --unattended'
echo "HOME=/home/ubuntu" >> .env
./svc.sh install

mkdir -p _work

chown -R ubuntu:ubuntu _work

su ubuntu -c './run.sh'

cleanup_agent() {
    echo "Stopping and unregistering the build agent..."
    su ubuntu -c './config.sh remove --unattended --token ${token}'
    ./svc.sh stop
    ./svc.sh uninstall
}

trap cleanup_agent SIGTERM SIGINT

while true; do
    sleep 60
done

The AMI image that the EC2 instance is running from already has docker installed. If I manually clone the repo and run:

docker run --rm -v $(pwd):$(pwd) -w $(pwd) andrewlock/nerdbank-gitversioning:latest get-version

it works fine


Solution

  • The docker container for nerdbank git versioning is very old, just create a new one, for instance:

    ARG DOTNET_VERSION="6.0"
    FROM "mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION}" AS builder
    ARG NBGV_VERSION="3.5.113"
    RUN dotnet tool install --global nbgv --version $NBGV_VERSION
    FROM "mcr.microsoft.com/dotnet/runtime:${DOTNET_VERSION}-bullseye-slim"
    COPY --from=builder /root/.dotnet/tools/ /opt/bin
    ENV PATH="/opt/bin:${PATH}"
    

    And then you can use that container.

    Or, install dotnet and the nbgv tool onto the build machine and use the cli tool directly.