Exit Codes¶
Commitizen handles expected exceptions through CommitizenException and returns different exit codes for different situations. This reference is useful when you need to ignore specific errors in your CI/CD pipeline or automation scripts.
All exit codes are defined in commitizen/exceptions.py.
Exit Code Reference¶
Ignoring Exit Codes¶
In some scenarios, you may want Commitizen to continue execution even when certain errors occur. This is particularly useful in CI/CD pipelines where you want to handle specific errors gracefully.
Using --no-raise Flag¶
The --no-raise (or -nr) flag allows you to specify exit codes that should not cause Commitizen to exit with an error. You can use either:
- Exit code numbers:
21,3,4 - Exit code names:
NO_INCREMENT,NO_COMMITS_FOUND,NO_VERSION_SPECIFIED - Mixed format:
21,NO_COMMITS_FOUND,4
Multiple exit codes can be specified as a comma-separated list.
Common Use Cases¶
Ignoring No Increment Errors¶
The most common use case is to ignore NoneIncrementExit (exit code 21) when running cz bump. This allows the command to succeed even when no commits are eligible for a version bump:
cz -nr 21 bump
Or using the exit code name:
cz -nr NO_INCREMENT bump
This is useful in CI pipelines where you want to run cz bump regularly, but don't want the pipeline to fail when there are no version-worthy commits.
Ignoring Multiple Exit Codes¶
You can ignore multiple exit codes at once:
cz --no-raise 21,3,4 bump
This example ignores:
21(NoneIncrementExit) - No eligible commits for bump3(NoCommitsFoundError) - No commits found4(NoVersionSpecifiedError) - Version not specified
Finding the Exit Code¶
If you encounter an error and want to ignore it, you can find the exit code in two ways:
Method 1: Check the Exit Code After Running¶
After running a Commitizen command that fails, check the exit code:
cz bump
echo $? # Prints the exit code (e.g., 21)
Then use that exit code with --no-raise:
cz -nr 21 bump
Method 2: Look Up the Exception¶
- Check the error message to identify the exception type
- Find the corresponding exit code in the table above
- Use that exit code with
--no-raise
For example, if you see NoneIncrementExit in the error, look it up in the table to find it's exit code 21, then use:
cz -nr 21 bump
Best Practices¶
- Document your usage: If you use
--no-raisein scripts or CI/CD, document why specific exit codes are ignored - Be specific: Only ignore exit codes you understand and have a reason to ignore
- Test thoroughly: Ensure that ignoring certain exit codes doesn't mask real problems in your workflow
- Use exit code names: When possible, use exit code names (e.g.,
NO_INCREMENT) instead of numbers for better readability
Example: CI/CD Pipeline¶
Here's an example of using --no-raise in a CI/CD pipeline:
# .github/workflows/release.yml
- name: Bump version
run: |
cz -nr NO_INCREMENT bump || true
# Continue even if no version bump is needed
This ensures the pipeline continues even when there are no commits eligible for a version bump.
