Search code examples
azure-pipelinesgitversion

AzurePipeline GitVersion step not finding the config.yaml


I've run out of idea trying to get my azure pipeline to work. I have 2 repositories, one for the pipelines templates and one for my project. Idea is to have generic pipelines ready to use in my projects just by referencing them.

"Pipelines" repository

The folder structure is :

  • commonLibrary
    • template.yaml
  • version
    • gitVersion.yaml
    • config.yaml

template.yaml

stages:
- stage: build 
  displayName: "Build"
  jobs:
  - job: build
    steps:
    - checkout: self
      persistCredentials: true
      submodules: true
      fetchDepth: 0 # https://github.com/GitTools/actions/blob/main/docs/examples/azure/gitversion/execute/usage-examples.md
      fetchTags: false

    - template: ../version/gitVersion.yaml@pipelines

gitVersion.yaml

steps:
    - task: gitversion/setup@0
      displayName: Install GitVersion
      inputs:
        versionSpec: '5.x'

    - task: gitversion/execute@0
      displayName: Determine Version
      inputs:
        useConfigFile: true
        configFilePath: ./config.yaml

config.yaml

assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatchTag
mode: ContinuousDeployment
tag-prefix: '[vV]'
continuous-delivery-fallback-tag: ci
major-version-bump-message: '\+semver:\s?(breaking|major)'
minor-version-bump-message: '\+semver:\s?(feature|minor)'
patch-version-bump-message: '\+semver:\s?(fix|patch)'
no-bump-message: '\+semver:\s?(none|skip)'
branches:
  feature:
    regex: ^feature[\/]
    tag: alpha
  main:
    regex: ^main$
    tag: beta
  release:
    regex: ^release[\/]
    tag: ''

"MicroService" repository

This is my microservice code, it contains an azure-pipelines.yaml file at the root of the repository:

trigger:
  batch: true
  branches:
    include:
    - main

resources:
  repositories:
    - repository: pipelines
      type: git
      name: Evently/Pipelines

stages:
  - template: commonLibrary/template.yaml@pipelines

Despite everything looking correct, when the pipeline runs, it fails "Determine Version" task. Here is the output :

##[error]Error: GitVersion configuration file not found at /home/vsts/work/1/s/config.yaml

I tried many different path ./config.yaml, config.yaml, config.yaml@pipelines, version/config.yaml, ./version/config.yaml etc...

What am I missing ? Thank you


Solution

  • It seems you didn't check out the "Pipelines" repository in your pipeline. So, it cannot find the config.yaml file. I added checkout: pipelines step in the template.yaml and can make it work with the following yaml.

    template.yaml

    stages:
    - stage: build 
      displayName: "Build"
      jobs:
      - job: build
        steps:
        - checkout: self
          persistCredentials: true
          submodules: true
          fetchDepth: 0 # https://github.com/GitTools/actions/blob/main/docs/examples/azure/gitversion/execute/usage-examples.md
          fetchTags: false
        - checkout: pipelines
        - bash:  tree
        - template: ../version/gitVersion.yaml@pipelines
    

    gitVersion.yaml

    steps:
        - task: gitversion/setup@0
          displayName: Install GitVersion
          inputs:
            versionSpec: '5.x'
        - task: gitversion/execute@0
          displayName: Determine Version
          inputs:
            targetPath: '$(Build.SourcesDirectory)/MicroService/'
            useConfigFile: true
            configFilePath: './Pipelines/version/config.yaml'
    

    Please note that when we check out multiple repositories in the pipeline, the source code is checked out into directories named after the repositories as a subfolder of s in $(Build.SourcesDirectory). So, the "MicroService" repository is in $(Build.SourcesDirectory)/MicroService/ and the "Pipelines" repository is in $(Build.SourcesDirectory)/Pipelines. I added the bash: tree task to print out the file structure.

    Here is my test result:

    enter image description here