asp.net-coreyamlcircleci

Issues with circleci related to gitversion


I have a circleci pipeline that generates a nuget package, and uploads it to nuget.org. So far It has been working just fine however It suddenly stopped working. This is the error

enter image description here

Here's the config.yml

version: 2.1

jobs:

  build-and-test:
    docker:
      - image: mcr.microsoft.com/dotnet/sdk:8.0
    steps:

      - checkout

      - run:
          name: Cambiar directorio
          command: cd ./Repo
         
      - run:
          name: Instalar Node
          command: apk add nodejs

      - run:
          name: Instalar NPM
          command: apk add npm

      - run:
          working_directory: ./Repo
          name: Ejecutar tests
          command: |
            dotnet test
            << pipeline.git.tag >>
      - run:
          working_directory: ./Repo
          name: Compilar version Release
          command: |
            dotnet build --configuration Release

      - run:
          name: Patchear imagen
          command: |
            apk add openssh git jq

      - run:
          name: Generar manifest
          command: |
            dotnet new tool-manifest

      - run:
          name: Instalar GitVersion
          command: |
            dotnet tool install GitVersion.Tool

      - run:
          working_directory: ./Repo/Components
          name: Generar paquete nuget
          command: |
            VERSION=$(dotnet gitversion | jq -r ".SemVer") 
            dotnet pack --configuration Release -p:Version=$VERSION -o ./outputs/packages/
            
      - store_artifacts:
          path: ./Repo/Components/outputs/packages
          destination: packages

      - persist_to_workspace:
          root: ./Repo/Components/outputs/packages
          paths:
            - "*.nupkg"
            - "*.snupkg"
  push:
    docker:
      - image: mcr.microsoft.com/dotnet/sdk:8.0
    steps:
      - attach_workspace:
          at: /tmp/workspace
      - run:
          name: Pushear a Nuget.org
          command: dotnet nuget push /tmp/workspace/*.* --api-key someapikey --skip-duplicate --source https://api.nuget.org/v3/index.json

workflows:
  setup:
    when:
      and:
        - equal: [ main, << pipeline.git.branch >> ]
    jobs:
      - build-and-test:
          filters:
            tags:
              only: /.*/
      - push:
          requires:
            - build-and-test
          context:
            - NuGet
          filters:
            tags:
              only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/

I've been investigating and recently I upgraded the system to .NET Core 8.0. Apparently Gitversion is now version 6.0 in order to be compatible with Net 8.0. https://github.com/GitTools/GitVersion/blob/main/BREAKING_CHANGES.md

I also tried replacing the jq library with fx, but I get this error SyntaxError: JSON value expected on line 1. I think dotnet gitversion is not outputting a proper json object.


Solution

  • I finally solved it by taking a look at the GitVersion.yml. I was using gitversion 6 in my pipeline, and gitversion 5 in my local environment so that's why I wasn't able to reproduce the error. Gitversion 6 contains breaking changes.

    First I make sure that the config.yml from circleci was valid (I used the circleci-cli for that task.) Then I updated gitversion to V6.0 in my local environment. Then I was able to reproduce the same error as the one reported by circle ci. It ended up being a malformed file (Gitversion.yml), some properties were renamed. By making sure the configuration file is valid it started working again. I haven't made any more changes besides fixing the config file. Hope someone finds this useful.