我们如何实现服务器端钩子或任何类似的解决方案来限制git push进入git server?例如,我们希望禁用包含 *.class文件的提交的推送。
q7solyqu1#
我不认为Azure DevOps使用钩子。您可以使用Branch Policies来使用外部验证服务(据我所知,这使用了Web钩子)。附加:this User Voice请求的状态表明以上是官方答案。但也许简单的情况是.gitignore和代码审查?
.gitignore
yqyhoc1h2#
我所做的是在Azure DevOps中使用构建选项和策略。这是我的azure-pipelines.yml文件:
azure-pipelines.yml
---trigger: branches: exclude: - '*'pool: vmImage: 'ubuntu-latest'steps: - script: sudo apt-get install python3-pip displayName: 'Install Python PIP' - script: sudo apt-get install python3-setuptools condition: succeeded() displayName: Install Python SetupTools - script: sudo pip3 install -r requirements.txt condition: succeeded() displayName: Install Python PIP Packages - task: PythonScript@0 inputs: scriptSource: filePath scriptPath: hooks/lint_checker.py pythonInterpreter: python3 condition: succeeded() displayName: Lint Checker
---
trigger:
branches:
exclude:
- '*'
pool:
vmImage: 'ubuntu-latest'
steps:
- script: sudo apt-get install python3-pip
displayName: 'Install Python PIP'
- script: sudo apt-get install python3-setuptools
condition: succeeded()
displayName: Install Python SetupTools
- script: sudo pip3 install -r requirements.txt
displayName: Install Python PIP Packages
- task: PythonScript@0
inputs:
scriptSource: filePath
scriptPath: hooks/lint_checker.py
pythonInterpreter: python3
displayName: Lint Checker
字符串
kkih6yb83#
使用分支策略并设置仅与PR合并,之后将禁用直接推送到分支,您可以为某些用户(构建用户或管理员)跳过这些策略
gopyfrb34#
我使用这个解决方案,正常工作,自动为所有用户.csproj中的本地git hooks和Pre-Build events的组合,检查.git\hooks中是否有pre-commit hook,如果没有,则从存储库中放置的hooks文件夹中复制它实施:在我的仓库里有一个hooks文件夹,包含2个文件:
csproj
git hooks
Pre-Build events
.git\hooks
pre-commit hook
@echo offecho Current location is: %cd%:: Check if the .git/hooks directory existsif not exist .git\hooks mkdir .git\hooks:: Copy your hook scripts to the .git/hooks directorycopy hooks\pre-commit .git\hooks\pre-commitecho Git hooks have been set up.
@echo off
echo Current location is: %cd%
:: Check if the .git/hooks directory exists
if not exist .git\hooks mkdir .git\hooks
:: Copy your hook scripts to the .git/hooks directory
copy hooks\pre-commit .git\hooks\pre-commit
echo Git hooks have been set up.
字符串在预构建事件中,我调用了setup-hooks.bat:x1c 0d1x
kokeuurv5#
这可以通过一个带有路径过滤器的分支策略来实现,你可以添加一个带有powershell的构建管道,它会返回一个失败的退出代码。
的数据
5条答案
按热度按时间q7solyqu1#
我不认为Azure DevOps使用钩子。
您可以使用Branch Policies来使用外部验证服务(据我所知,这使用了Web钩子)。
附加:this User Voice请求的状态表明以上是官方答案。
但也许简单的情况是
.gitignore
和代码审查?yqyhoc1h2#
我所做的是在Azure DevOps中使用构建选项和策略。这是我的
azure-pipelines.yml
文件:字符串
kkih6yb83#
使用分支策略并设置仅与PR合并,之后将禁用直接推送到分支,您可以为某些用户(构建用户或管理员)跳过这些策略

gopyfrb34#
我使用这个解决方案,正常工作,自动为所有用户.
csproj
中的本地git hooks
和Pre-Build events
的组合,检查.git\hooks
中是否有pre-commit hook
,如果没有,则从存储库中放置的hooks文件夹中复制它实施:
在我的仓库里有一个hooks文件夹,包含2个文件:
设置挂钩:
字符串
在预构建事件中,我调用了setup-hooks.bat:x1c 0d1x
kokeuurv5#
这可以通过一个带有路径过滤器的分支策略来实现,你可以添加一个带有powershell的构建管道,它会返回一个失败的退出代码。
的数据