Integrate Cline CLI into a CI/CD Pipeline — Detailed Sequence of Steps
1. Use the askfollowupquestion tool to determine which platform the user wants to target:
1. Use the askfollowupquestion tool to determine which platform the user wants to target:
--- description: "Workflow for integrating the Cline CLI as an autonomous agent inside CI/CD pipelines (GitHub Actions, GitLab CI, etc.) to automate code review, test generation, documentation, and more." author: "Cline Community" version: "1.0" category: "CI/CD" tags: ["ci-cd", "cline-cli", "github-actions", "gitlab-ci", "automation", "devops"] globs: ["*.*"] ---
<task name="Integrate Cline CLI into a CI/CD Pipeline">
<task_objective> Guide the user through adding the Cline CLI (`claude`) as an autonomous agent step in their CI/CD pipeline. The workflow identifies what tasks to automate (code review, test generation, documentation, etc.), configures secrets securely, and generates a working pipeline configuration file that invokes the Cline CLI with appropriate flags. </task_objective>
<detailed_sequence_steps>
<ask_followup_question>
<question>Which CI/CD platform would you like to integrate the Cline CLI into?</question>
<options>["GitHub Actions", "GitLab CI", "Other (I'll specify)"]</options>
</ask_followup_question> <ask_followup_question>
<question>What tasks should the Cline CLI perform in your pipeline? Select the primary use case to start with — you can add more later.</question>
<options>["Automated PR code review", "Generate or update tests for changed files", "Auto-fix lint / type errors", "Generate or update documentation", "Custom task (I'll describe it)"]</options>
</ask_followup_question>🚨 **CRITICAL: Never store API keys in plaintext.** Keys must ONLY be stored in the CI platform's encrypted secrets manager. Never hardcode keys in pipeline config files, commit them to version control, echo them in logs, or pass them as command-line arguments.
**GitHub Actions:**
1. Go to your repo → Settings → Secrets and variables → Actions
2. Click "New repository secret"
3. Name: ANTHROPIC_API_KEY
4. Value: paste your key (it will be encrypted at rest)
5. Click "Add secret"
The key is encrypted by GitHub and only exposed to pipeline runs
as a masked environment variable. It will never appear in logs.**GitLab CI:**
1. Go to your project → Settings → CI/CD → Variables
2. Click "Add variable"
3. Key: ANTHROPIC_API_KEY
4. Value: paste your key
5. Check "Mask variable" (prevents it from appearing in job logs)
6. Optionally check "Protect variable" (limits to protected branches)
7. Click "Add variable" <ask_followup_question>
<question>Have you added your ANTHROPIC_API_KEY as an encrypted secret in your CI platform's settings?</question>
<options>["Yes, the secret is configured", "No, I need help with this step"]</options>
</ask_followup_question> name: Cline PR Review
on:
pull_request:
types: [opened, synchronize]
jobs:
cline-review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Cline CLI
run: npm install -g @anthropic-ai/claude-code
- name: Get PR diff
run: git diff origin/${{ github.base_ref }}...HEAD > /tmp/pr-diff.txt
# ANTHROPIC_API_KEY is injected from GitHub's encrypted secrets store.
# It is masked in logs and never written to disk in plaintext.
- name: Run Cline review
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
claude -p "Review the following code changes from a pull request. \
Focus on bugs, security issues, performance problems, and readability. \
Provide a concise summary of findings. \
$(cat /tmp/pr-diff.txt)" \
--permission-mode plan \
--max-turns 5 \
--output-format json > /tmp/review-result.json
- name: Post review comment
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
REVIEW=$(jq -r '.result' /tmp/review-result.json)
gh pr comment ${{ github.event.pull_request.number }} --body "$REVIEW" name: Cline Test Generation
on:
push:
branches: [main]
jobs:
generate-tests:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Cline CLI
run: npm install -g @anthropic-ai/claude-code
- name: Detect changed files
id: changes
run: echo "files=$(git diff --name-only HEAD~1 HEAD | tr '\n' ' ')" >> $GITHUB_OUTPUT
# API key sourced exclusively from encrypted secrets — never plaintext.
- name: Generate tests
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
claude -p "Analyze these changed files and generate or update \
corresponding unit tests following existing test patterns in the \
project: ${{ steps.changes.outputs.files }}" \
--permission-mode acceptEdits \
--max-turns 15
- name: Create PR with generated tests
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "cline-bot"
git config user.email "cline-bot@users.noreply.github.com"
BRANCH="cline/auto-tests-$(date +%s)"
git checkout -b "$BRANCH"
git add -A
git diff --cached --quiet && echo "No changes" && exit 0
git commit -m "test: add generated tests for recent changes"
git push origin "$BRANCH"
gh pr create --title "test: auto-generated tests" \
--body "Tests generated by Cline CLI for recent changes." \
--base main --head "$BRANCH" --disallowedTools "Bash(rm -rf),Bash(git push --force)" <ask_followup_question>
<question>The pipeline config is ready. Would you like to test it now by pushing a commit or opening a test PR?</question>
<options>["Yes, I'll trigger it now", "No, I'll test it later"]</options>
</ask_followup_question></detailed_sequence_steps>
</task>