Pattern Matching in CI/CD Log Parsing with Regex Tester
Extract error codes, version numbers, and deployment IDs from CI/CD build logs using regex pattern matching. Includes GitHub Actions workflow YAML with grep and sed examples.
The Problem
Your deployment pipeline produces verbose logs and you need to extract specific values — build version, error codes, deployed commit SHA, test coverage percentage — to use in notifications, release notes, or gating conditions.
Why This Matters
Log parsing with regex is 10x faster than string manipulation scripts. A single regex in a GitHub Actions step can extract a semantic version from a 500-line build log, trigger different workflow paths based on error codes, or auto-populate a Slack notification with deployment details.
Step-by-Step Instructions
Test your regex pattern in the tool below
Paste a sample of your CI log into the Regex Tester. Build and test your pattern interactively — seeing match highlights in real time is far faster than iterating on grep flags in a workflow.
Use <code>grep -oP</code> for PCRE matching in your workflow
grep -oP '(?<=version: )\d+\.\d+\.\d+' extracts just the match. The -P flag enables Perl-Compatible Regex (available on Ubuntu runners). Combine with head -1 to get the first match.
Write extracted values to GitHub step outputs
Echo extracted values to $GITHUB_OUTPUT: echo "version=$(grep -oP ... <<< "$LOG")" >> $GITHUB_OUTPUT. Reference them later as ${{ steps.parse.outputs.version }}.
Gate workflow steps on regex matches
Use if: contains(steps.parse.outputs.errors, 'CRITICAL') to conditionally run notification or rollback steps only when specific patterns are found in logs.
Try It Now — Regex Tester
Open full page →All processing happens in your browser — no data is sent to any server.
Before & After Example
Build log output: [INFO] Compiling project... [INFO] Running tests... 234 passed, 0 failed [INFO] Building Docker image: myapp:latest [INFO] Successfully tagged myapp:3.14.2-rc1 [INFO] Pushing to registry.example.com... [SUCCESS] Deployment complete # How do you extract "3.14.2-rc1" reliably?
- name: Parse build log for version and status
id: parse_log
run: |
BUILD_LOG=$(cat build.log)
# Extract semantic version (e.g., 3.14.2-rc1)
VERSION=$(echo "$BUILD_LOG" | grep -oP '(?<=myapp:)\d+\.\d+\.\d+[\w.-]*' | head -1)
# Extract test count
TESTS=$(echo "$BUILD_LOG" | grep -oP '\d+(?= passed)')
# Check for any ERROR lines
ERRORS=$(echo "$BUILD_LOG" | grep -cP '^\[ERROR\]' || echo "0")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tests_passed=$TESTS" >> $GITHUB_OUTPUT
echo "error_count=$ERRORS" >> $GITHUB_OUTPUT
- name: Fail if errors detected
if: steps.parse_log.outputs.error_count != '0'
run: |
echo "Build had ${{ steps.parse_log.outputs.error_count }} errors"
exit 1
- name: Create GitHub Release
uses: actions/create-release@v1
with:
tag_name: v${{ steps.parse_log.outputs.version }}
Frequently Asked Questions
Does <code>grep -P</code> work on macOS GitHub runners?
macOS uses BSD grep which does not support -P (PCRE). Use grep -E for extended regex, or install grep via Homebrew: brew install grep and use ggrep -P.
How do I handle regex with special characters in shell?
Single-quote your regex in shell: grep -oP '\d+\.\d+'. Avoid double quotes, which allow shell expansion of backslashes. For complex patterns, store the regex in a variable first.
Can I use named capture groups in GitHub Actions?
Yes, with Python or Node.js steps. Use python3 -c "import re; m = re.search(r'(?P<version>\d+\.\d+)', log); print(m.group('version'))" for clean extraction with named groups.
Related Workflows
Want the full Regex Tester experience?
Open the standalone tool for more space, keyboard shortcuts, and additional features.
Open Regex Tester →