Azure devops -服务器端git hooks

ahy6op9u  于 2023-11-15  发布在  Git
关注(0)|答案(5)|浏览(177)

我们如何实现服务器端钩子或任何类似的解决方案来限制git push进入git server?
例如,我们希望禁用包含 *.class文件的提交的推送。

q7solyqu

q7solyqu1#

我不认为Azure DevOps使用钩子。
您可以使用Branch Policies来使用外部验证服务(据我所知,这使用了Web钩子)。
附加:this User Voice请求的状态表明以上是官方答案。
但也许简单的情况是.gitignore和代码审查?

yqyhoc1h

yqyhoc1h2#

我所做的是在Azure DevOps中使用构建选项和策略。这是我的azure-pipelines.yml文件:

  1. ---
  2. trigger:
  3. branches:
  4. exclude:
  5. - '*'
  6. pool:
  7. vmImage: 'ubuntu-latest'
  8. steps:
  9. - script: sudo apt-get install python3-pip
  10. displayName: 'Install Python PIP'
  11. - script: sudo apt-get install python3-setuptools
  12. condition: succeeded()
  13. displayName: Install Python SetupTools
  14. - script: sudo pip3 install -r requirements.txt
  15. condition: succeeded()
  16. displayName: Install Python PIP Packages
  17. - task: PythonScript@0
  18. inputs:
  19. scriptSource: filePath
  20. scriptPath: hooks/lint_checker.py
  21. pythonInterpreter: python3
  22. condition: succeeded()
  23. displayName: Lint Checker

字符串

展开查看全部
kkih6yb8

kkih6yb83#

使用分支策略并设置仅与PR合并,之后将禁用直接推送到分支,您可以为某些用户(构建用户或管理员)跳过这些策略

gopyfrb3

gopyfrb34#

我使用这个解决方案,正常工作,自动为所有用户.
csproj中的本地git hooksPre-Build events的组合,检查.git\hooks中是否有pre-commit hook,如果没有,则从存储库中放置的hooks文件夹中复制它
实施:
在我的仓库里有一个hooks文件夹,包含2个文件:

  1. setup-hooks.bat
  2. pre-commit
    设置挂钩:
  1. @echo off
  2. echo Current location is: %cd%
  3. :: Check if the .git/hooks directory exists
  4. if not exist .git\hooks mkdir .git\hooks
  5. :: Copy your hook scripts to the .git/hooks directory
  6. copy hooks\pre-commit .git\hooks\pre-commit
  7. echo Git hooks have been set up.

字符串
在预构建事件中,我调用了setup-hooks.bat:x1c 0d1x

展开查看全部
kokeuurv

kokeuurv5#

这可以通过一个带有路径过滤器的分支策略来实现,你可以添加一个带有powershell的构建管道,它会返回一个失败的退出代码。


的数据

相关问题