gaelcolas / Sampler

Module template with build pipeline and examples, including DSC elements.
MIT License
171 stars 42 forks source link

New Azure Pipelines does shallow fetch by default #424

Closed johlju closed 1 year ago

johlju commented 1 year ago

Problem description

New Azure Pipelines do shallow fetch by default which make GitVersion to fail since all commit history is not available.

Verbose logs

Not available

How to reproduce

Run the current pipeline in a newly created Azure Pipelines pipeline.

Expected behavior

Should not do shallow fetch.

Current behavior

Does shallow fetch.

Suggested solution

Add the following to azure-pipelines.yml:

variables:
  Agent.Source.Git.ShallowFetchDepth: 0

Operating system the target node is running

n/a

PowerShell version and build the target node is running

n/a

Module version used

n/a
fslef commented 1 year ago

@johlju, Is it the reasons why I'm having this issue when deploying the pipeline (it was my first attempt on this project today)

Starting: Calculate ModuleVersion (GitVersion)
==============================================================================
Task         : PowerShell
Description  : Run a PowerShell script on Linux, macOS, or Windows
Version      : 2.212.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
==============================================================================
Generating script.
========================== Starting Command Output ===========================
/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command . '/home/vsts/work/_temp/0f944673-58bd-4ea6-8125-ce009ad98b07.ps1'
You can invoke the tool using the following command: dotnet-gitversion
Tool 'gitversion.tool' (version '5.12.0') was successfully installed.
ConvertFrom-Json: /home/vsts/work/_temp/0f944673-58bd-4ea6-8125-ce009ad98b07.ps1:4
Line |
   4 |  $gitVersionObject = dotnet-gitversion | ConvertFrom-Json
     |                                          ~~~~~~~~~~~~~~~~
     | Conversion from JSON failed with error: Error parsing Infinity value.
     | Path '', line 1, position 1.

##[error]PowerShell exited with code '1'.
Finishing: Calculate ModuleVersion (GitVersion)

My GitVersion.yml is the following:

mode: ContinuousDelivery
next-version: 0.0.1
major-version-bump-message: '(breaking\schange|breaking|major)\b'
minor-version-bump-message: '(adds?|features?|minor)\b'
patch-version-bump-message: '\s?(fix|patch)'
no-bump-message: '\+semver:\s?(none|skip)'
assembly-informational-format: '{NuGetVersionV2}+Sha.{Sha}.Date.{CommitDate}'
branches:
  master:
    tag: preview
    regex: ^main$
  pull-request:
    tag: PR
  feature:
    tag: useBranchName
    increment: Minor
    regex: f(eature(s)?)?[\/-]
    source-branches: ['master']
  hotfix:
    tag: fix
    increment: Patch
    regex: (hot)?fix(es)?[\/-]
    source-branches: ['master']

ignore:
  sha: []
  merge-message-formats: {}

feature:
  tag: useBranchName
  increment: Minor
  regex: f(eature(s)?)?[/-]
  source-branches: ['master']

hotfix:
  tag: fix
  increment: Patch
  regex: (hot)?fix(es)?[/-]
  source-branches: ['master']
johlju commented 1 year ago

Yes it is. Either add the above line to azure-pipelines.yml or manually uncheck the box in the pipeline

image

johlju commented 1 year ago

I haven't verified that the line works in Azure Pipelines, but assuming since I saw that @raandree did add it in a PR and Raimund first reported the issue. 🙂

fslef commented 1 year ago

I tried this but it was not successful for me

variables:
  buildFolderName: output
  buildArtifactName: output
  testResultFolderName: testResults
  defaultBranch: main
  Agent.Source.Git.ShallowFetchDepth: 0

But I'm not used to work with pipeline, so maybe I didn't update it the right way.

fslef commented 1 year ago

BTW, unchecking the option manually worked

johlju commented 1 year ago

@fslef looks like you did it correctly. Thanks for confirming that it might not work. I will double check with @raandree.

raandree commented 1 year ago

I am using this in my repo with AZ Pipelines since quite some time. Sorry that I didn't forward it earlier.

And yes, that solved the issue with GitVersion.

fslef commented 1 year ago

Maybe as my pipeline was not yet merged to main was the root cause. (I was stuck to approve a PR)