简体   繁体   English

我在 Azure CI 管道中实施 commitlint,但无法使用 --from 标签获取对另一个分支的引用以正常工作

[英]I am implementing commitlint in an Azure CI pipeline but cannot get the reference to another branch with the --from tag to work

I am working with a yaml file in my .net core project in Azure DevOps which looks like this:我在 Azure DevOps 的 .net 核心项目中使用 yaml 文件,如下所示:

trigger:
- main

pool:
  vmImage: windows-latest

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

stages:
- stage: LintCommitMessages
  jobs:
  - job: Validate
    displayName: Validate
    steps:
    - pwsh: |      
        npm install @commitlint/config-conventional @commitlint/cli
        npx commitlint --from refs/remotes/origin/main
      displayName: Validate commit message

I keep getting the following error message:我不断收到以下错误消息:

Starting: Validate commit message
==============================================================================
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 ===========================
"C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\112b3b4e-829d-4fde-a720-44510788ca2d.ps1'"

added 200 packages, and audited 201 packages in 16s

27 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
D:\a\1\s\node_modules\@commitlint\cli\lib\cli.js:123
        throw err;
        ^

Error: fatal: ambiguous argument 'refs/remotes/origin/main..HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

    at Transform._transform (D:\a\1\s\node_modules\git-raw-commits\index.js:84:30)
    at Transform._read (D:\a\1\s\node_modules\readable-stream\lib\_stream_transform.js:177:10)
    at Transform._write (D:\a\1\s\node_modules\readable-stream\lib\_stream_transform.js:164:83)
    at doWrite (D:\a\1\s\node_modules\readable-stream\lib\_stream_writable.js:409:139)
    at writeOrBuffer (D:\a\1\s\node_modules\readable-stream\lib\_stream_writable.js:398:5)
    at Transform.Writable.write (D:\a\1\s\node_modules\readable-stream\lib\_stream_writable.js:307:11)
    at Socket.ondata (node:internal/streams/readable:754:22)
    at Socket.emit (node:events:525:35)
    at Socket.emit (node:domain:489:12)
    at addChunk (node:internal/streams/readable:315:12)
##[error]PowerShell exited with code '1'.
Finishing: Validate commit message

Anyone who has had the same issue?谁有过同样的问题?

I have tried most variations of the path that I can come up with so I must be misunderstanding how to enter this one completely.我已经尝试了我能想出的大多数路径变体,所以我一定误解了如何完全进入这个路径。

I have also tried this variant and then the pipeline runs but it does not capture any of the errors that I try entering in the commit messages so everything passes through:我也尝试过这个变体,然后管道运行但它没有捕获我尝试在提交消息中输入的任何错误,所以一切都通过了:

trigger:
- main

pool:
  vmImage: windows-latest

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  main_branch: ''

stages:
- stage: LintCommitMessages
  jobs:
  - job: lint
    pool:
      vmImage: ubuntu-latest
    displayName: Lint commit message
    steps:
    - script: npm install @commitlint/{config-conventional,cli}
      displayName: Install commitlint
    - script: |
        main_branch=$(git branch -a | grep origin/main$ || git branch -a | grep origin/master$)
        npx commitlint --from ${main_branch} --verbose
      displayName: Run commitlint

This is the result:这是结果:

Starting: Run commitlint
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.212.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/de0c00c9-35ff-41e6-9297-062f15e54e74.sh
⧗   input: Merge pull request 13 from feat/change-pipeline into main
✔   found 0 problems, 0 warnings
Finishing: Run commitlint

I found out the solution now and it was a setting in Azure DevOps for the pipeline.我现在找到了解决方案,它是管道的 Azure DevOps 中的一个设置。 By navigating to the pipeline and then select edit you can then select triggers in the top right corner:通过导航到管道,然后 select 编辑,您可以在右上角使用 select 触发器:

Trigger扳机

You will then see a menu item named YAML and after clicking that you can select Get sources.然后您将看到一个名为 YAML 的菜单项,单击该菜单项后您可以 select 获取源。 At the bottom of the options that comes up to the right there is a choice called "Shallow fetch", you need to uncheck this one and then everything will work:-)在右侧出现的选项底部有一个名为“Shallow fetch”的选项,您需要取消选中此选项,然后一切正常:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM