In this article, you can find information on how to integrate YELP detect-secrets into your Azure DevOps Pipeline. The proposed code can be part of the classic CI process or (preferred way) build validation for PRs before merging to the main branch.
Azure DevOps Pipeline
Proposed Azure DevOps Pipeline contains multiple steps described below:
Set Python 3 as default
Install detect-secrets using pip
Run detect-secrets tool
Publish results in the Pipeline Artifact
NOTE: It's an optional step, but for future investigation .json file with results may be helpful.
Analyzing detect-secrets results
NOTE: This step does a simple analysis of the .json file. If any secret has been detected, then break the build with exit code 1.
NOTE: The below example has 2 jobs: for Linux and Windows agents. You do not have to use both jobs - just adjust the pipeline to your needs.
NOTE: Windows example does not use the latest version of detect-secrets. It is related to the bug in the detect-secret tool (see more in Issue#452). It is highly recommended to monitor the fix for the issue and use the latest version if possible, by removing version tag ==1.0.3 in the pip install command.