Azure devops - server-side git hooks

孤街醉人 提交于 2020-05-15 05:56:45

问题


How can we implement server-side hooks, or any similar solution, to restrict git push into git server?

For example, we want to disable push of commits containing *.class files.


回答1:


I don't think Azure DevOps uses hooks.

You can use Branch Policies to make use of an external validation service (as I understand it this uses web hooks).

Additional: the status of this User Voice request indicates the above is the official answer.

But maybe the simple case would be .gitignore and code reviews?




回答2:


Use branch policies and set merge only with PR, after that direct push to the branch will be disabled, you can skip these policies for certain users (build users or admins)




回答3:


What I do is using build option together with policies in Azure DevOps. This is my azure-pipelines.yml file:

---
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


来源:https://stackoverflow.com/questions/54213052/azure-devops-server-side-git-hooks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!