0

I see that I can use pre-commit with pipelines, is there a way to set up the yaml file for azure pipeline to use git commit --no-verify when if fails for specific cases? or is there a way to troubleshoot the pipeline when the issue occurs?

this is what I have for the yaml file

  pool:
    vmImage: ubuntu-18.04
  variables:
    PRE_COMMIT_HOME: $(Pipeline.Workspace)/pre-commit-cache

  steps:
  - task: UsePythonVersion@0
    inputs:
      versionSpec: ${{ parameters.python }}
  - script: |
      echo "##vso[task.setvariable variable=PY]$(python -VV)"
    displayName: set version variables
  - task: CacheBeta@0
    inputs:
      key: pre-commit | .pre-commit-config.yaml | "$(PY)" 
      path: $(PRE_COMMIT_HOME)

  - script: python -m pip install --upgrade pre-commit
    displayName: install pre-commit
  - script: pre-commit run --all-files --show-diff-on-failure
    displayName: run pre-commit
anthony sottile
  • 61,815
  • 15
  • 148
  • 207
codher
  • 1
  • is there something stopping you from `|| true` or `|| git commit`? what behaviour are you trying to get out of this? – anthony sottile Sep 18 '20 at 16:34
  • @AnthonySottile I want the pre commit hooks to run in the pipeline but in instances where the static analysis fails because of hook that's flagging an error for reasons that are acceptable, I would like to be able to override in the pipeline. I know locally I can run `git commit --no-verify`, there something similar I can do within the pipeline? – codher Sep 18 '20 at 20:15
  • yeah you'd use `|| true`, or `SKIP` environment variable -- but `--no-verify` just skips the whole thing so you'd just not run it at all right? – anthony sottile Sep 18 '20 at 20:22
  • @AnthonySottile oh I see, yes, and that's not what I want, thanks for clearing that up. – codher Sep 18 '20 at 20:35

1 Answers1

1

Check the documentation here:

Not all hooks are perfect so sometimes you may need to skip execution of one or more hooks. pre-commit solves this by querying a SKIP environment variable. The SKIP environment variable is a comma separated list of hook ids. This allows you to skip a single hook instead of --no-verifying the entire commit.

$ SKIP=flake8 git commit -m "foo"

Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39