Skip to content
| Marketplace
Sign in
Azure DevOps>Azure Pipelines>ADO Coding Agent
ADO Coding Agent

ADO Coding Agent

twdeveloper

|
8 installs
| (0) | Preview
AI-powered task using GitHub Copilot CLI. Processes PR comments with AI commands or executes custom prompts in branch builds. Auto-commits changes.
Get it free

ADO Coding Agent

Azure DevOps Pipeline Task that integrates GitHub Copilot CLI for AI-powered code generation. Works in both PR context (processes AI commands from comments) and branch builds (executes custom Copilot prompts). Automatically commits and pushes changes.

正體中文 | 日本語

Features

  • 🤖 AI-Powered Code Generation: Integrates with GitHub Copilot CLI to process natural language commands
  • 💬 PR Comment Commands: Execute AI commands by commenting AI: <your request> in Pull Requests
  • 🔄 Automatic Git Operations: Commits and pushes changes back to PR source branch
  • 📝 Thread Management: Replies in the original comment thread and auto-closes processed threads
  • ⚙️ Pre-Command Execution: Run custom shell commands before task execution
  • 🎯 Custom Copilot Prompts: Execute one-time Copilot commands at task startup
  • 🔒 Smart Change Detection: Only commits and pushes when actual file changes are detected

Prerequisites

1. GitHub Copilot CLI Access

Ensure you have a valid GitHub Copilot subscription and can access GitHub Copilot CLI. The task automatically installs @github/copilot npm package globally.

2. GitHub Token (Required)

You need a GitHub Personal Access Token (PAT) to use GitHub Copilot CLI:

  1. Go to GitHub Settings → Developer settings → Personal access tokens → Tokens (classic)
  2. Generate a new token with copilot scope
  3. Store the token in Azure DevOps:
    • Go to Pipelines → Library → Secure files/Variable groups
    • Create a variable group or add to pipeline variables
    • Add a secret variable named GITHUB_TOKEN

3. Azure DevOps Permissions

Enable OAuth Token Access

In your pipeline YAML, you MUST enable scripts to access the OAuth token:

steps:
  - checkout: self
    persistCredentials: true
    fetchDepth: 0

Additionally, ensure the Build Service has proper permissions:

  1. Go to Project Settings → Repositories → Select your repository
  2. Go to Security tab
  3. Find [Your Project] Build Service ([Your Organization]) user
  4. Grant the following permissions:
    • ✅ Contribute: Allow
    • ✅ Contribute to pull requests: Allow
    • ✅ Create branch: Allow
    • ✅ Read: Allow

Enable OAuth Token in Pipeline Settings

  1. Go to your pipeline
  2. Click Edit → ... (More actions) → Triggers
  3. Go to YAML tab → Get sources
  4. Enable: ☑️ Allow scripts to access the OAuth token

Usage

Supported Contexts

This task works in two different contexts:

1. Pull Request (PR) Context - Full Features ✅

  • ✅ Pre-commands execution
  • ✅ GitHub Copilot CLI installation
  • ✅ Custom copilotPrompt execution
  • ✅ AI commands from PR comments (e.g., AI: fix the bug)
  • ✅ Thread replies and auto-close
  • ✅ Commit & Push

When to use: Include this task in your PR pipeline to enable AI-powered code modifications via PR comments.

2. Branch Build Context - Limited Features ⚙️

  • ✅ Pre-commands execution
  • ✅ GitHub Copilot CLI installation
  • ✅ Custom copilotPrompt execution
  • ❌ AI commands from PR comments (no PR available)
  • ✅ Commit & Push

When to use: Use in branch builds (e.g., main, develop) to run one-time Copilot tasks via copilotPrompt parameter.


Basic Pipeline YAML (PR Context)

trigger:
  - main

pr:
  - main
  - develop

pool:
  vmImage: 'ubuntu-latest'

variables:
  - group: github-secrets  # Variable group containing GITHUB_TOKEN

steps:
  - checkout: self
    persistCredentials: true
    fetchDepth: 0

  - task: ADOCodingAgent@0
    displayName: "ADO Coding Agent"
    inputs:
      githubToken: $(GITHUB_TOKEN)  # Required for GitHub Copilot CLI
      commitMessage: "chore: AI auto-fix for PR"
      dryRun: false

With Pre-Commands

  - task: ADOCodingAgent@0
    displayName: "ADO Coding Agent"
    inputs:
      githubToken: $(GITHUB_TOKEN)
      preCommands: |
        npm install
        npm run build
      failOnPreCmdError: true
      commitMessage: "feat: AI-generated changes"

With Custom Copilot Prompt

  - task: ADOCodingAgent@0
    displayName: "ADO Coding Agent"
    inputs:
      githubToken: $(GITHUB_TOKEN)
      copilotPrompt: |
        Review all TypeScript files and add JSDoc comments
        to exported functions that are missing documentation
      commitMessage: "docs: Add JSDoc comments"

Branch Build (Non-PR Context)

Use in regular branch builds to run automated Copilot tasks:

trigger:
  - main
  - develop

pool:
  vmImage: 'ubuntu-latest'

variables:
  - group: github-secrets

steps:
  - checkout: self
    persistCredentials: true
    fetchDepth: 0

  - task: ADOCodingAgent@0
    displayName: "Automated Code Quality Check"
    inputs:
      githubToken: $(GITHUB_TOKEN)
      copilotPrompt: |
        Review all code files and fix any linting errors,
        add missing error handling, and ensure code follows
        project coding standards
      commitMessage: "chore: Automated code quality improvements"
      dryRun: false

Note: In branch builds, PR comment processing is automatically skipped. Only copilotPrompt and preCommands are executed.


Using AI Commands in PR Comments

Simply add a comment in your Pull Request starting with AI::

Example 1: Add a new feature

AI: Create a new function in src/utils.js that validates email addresses using regex

Example 2: Fix a bug

AI: Fix the null pointer exception in the getUserProfile function in src/auth.ts

Example 3: Refactor code

AI: Refactor the calculateTotal function in src/cart.js to use reduce instead of forEach

Example 4: Add tests

AI: Add unit tests for the loginUser function in tests/auth.test.js

The task will:

  1. ✅ Detect the AI command in PR comments (only in active/open threads)
  2. ✅ Execute the command using GitHub Copilot CLI
  3. ✅ Commit and push any file changes
  4. ✅ Reply with the result in the same comment thread
  5. ✅ Automatically close the thread after processing

Task Parameters

Required Parameters

githubToken (string) ✅ Required

GitHub Personal Access Token for Copilot CLI authentication

  • Purpose: Authenticates with GitHub Copilot service to enable AI-powered code generation
  • How to get: Create a PAT at GitHub Settings → Developer settings → Personal access tokens
  • Required scope: copilot (read access to GitHub Copilot)
  • Storage: Store as a secret variable in Azure DevOps Variable Groups or Pipeline Variables
  • Usage: githubToken: $(GITHUB_TOKEN)
  • Security: Never commit this token to source code; always use pipeline variables

Optional Parameters

commitMessage (string)

Git commit message template

  • Default: AI: auto-commit by ADO Coding Agent
  • Purpose: Customize the commit message for changes made by the task
  • Template variables: PR number is automatically appended as #${prId}
  • Examples:
    • feat: AI-generated improvements
    • fix: AI-powered bug fixes
    • docs: AI documentation updates
  • Best practices: Follow conventional commits format for better changelog generation

dryRun (boolean)

Test mode - commits locally without pushing to remote

  • Default: false
  • Purpose: Test the task behavior without affecting the remote repository
  • When enabled:
    • ✅ All AI commands are processed
    • ✅ Files are modified locally
    • ✅ Changes are committed to local git
    • ❌ No push to remote branch
    • ✅ Comments are posted to PR indicating dry-run mode
  • Use cases:
    • Testing task configuration
    • Validating AI command behavior
    • Debugging without affecting production code

preCommands (multiline)

Shell commands executed before main task logic

  • Default: None
  • Purpose: Run setup, build, or validation commands before processing AI requests
  • Format: One command per line, or comma-separated
  • Shell detection: Automatically uses bash if available, otherwise falls back to system shell (PowerShell/cmd on Windows)
  • Examples:
    preCommands: |
      npm install
      npm run build
      npm test
    
    Or:
    preCommands: 'npm install, npm run lint'
    
  • Common use cases:
    • Install dependencies: npm install, pip install -r requirements.txt
    • Run builds: npm run build, dotnet build
    • Execute tests: npm test, pytest
    • Environment setup: export NODE_ENV=production
  • Environment variable alternative: Can also use PRE_COMMANDS env var

failOnPreCmdError (boolean)

Fail entire task if any pre-command fails

  • Default: false
  • Purpose: Control task behavior when pre-commands encounter errors
  • When false (default):
    • Pre-command failures are logged as warnings
    • Task continues execution
    • Useful for non-critical setup steps
  • When true:
    • First pre-command failure stops task execution
    • Task is marked as failed
    • No AI commands are processed
    • Useful for critical dependencies or builds
  • Exit code detection: Monitors command exit codes (0 = success, non-zero = failure)
  • Environment variable alternative: Can also use FAIL_ON_PRECMD_ERROR=1 env var

copilotPrompt (multiline)

One-time GitHub Copilot CLI prompt executed at task startup

  • Default: None
  • Purpose: Execute a single AI task before processing PR comments
  • Execution timing: Runs after git initialization and before processing AI commands from PR comments
  • Format: Multi-line text supporting natural language instructions
  • File change tracking: All changes are tracked and included in the final commit
  • Examples:
    copilotPrompt: |
      Review all TypeScript files and add JSDoc comments
      to exported functions that are missing documentation
    
    copilotPrompt: |
      Find all TODO comments in the codebase and create
      corresponding GitHub issues
    
  • Use cases:
    • Automated code quality improvements
    • Documentation generation
    • Consistent formatting across files
    • Refactoring tasks
  • Difference from PR comments:
    • PR comments (AI: ...): Interactive, per-comment processing with thread replies
    • copilotPrompt: One-time execution at task startup, changes included in main commit

How It Works

Execution Flow

1. Run Pre-Commands (if specified)
   ↓
2. Install GitHub Copilot CLI globally
   ↓
3. Set GITHUB_TOKEN environment variable
   ↓
4. Initialize Git (fetch, checkout PR branch)
   ↓
5. Configure Git user identity
   ↓
6. Execute Custom Copilot Prompt (if specified)
   ↓
7. Fetch all PR comment threads
   ↓
8. Process AI commands (skip closed threads)
   ↓
9. Check for file changes
   ↓
10. Commit & Push (if changes detected)
    ↓
11. Reply to PR with results

Thread Management

  • Active Threads: AI commands in open/active threads are processed
  • Closed Threads: Automatically skipped to prevent duplicate processing
  • Auto-Close: After processing, threads are automatically closed
  • Thread Replies: Responses appear in the original comment thread (not as new threads)

Advanced Configuration

Environment Variables

You can also configure the task using environment variables:

  - task: ADOCodingAgent@0
    env:
      GITHUB_TOKEN: $(GITHUB_TOKEN)
      PRE_COMMANDS: 'npm install, npm test'
      FAIL_ON_PRECMD_ERROR: '1'

Using Bash for Pre-Commands

The task automatically detects if bash is available and uses it for pre-commands. On Windows agents without bash, it falls back to the system shell (PowerShell/cmd).

Dry-Run Mode

Test the task without pushing changes:

  - task: ADOCodingAgent@0
    inputs:
      githubToken: $(GITHUB_TOKEN)
      dryRun: true  # No push, only local commits

Troubleshooting

Common Issues

1. "Failed to install @github/copilot"

  • Ensure the build agent has internet access
  • Check npm is installed and accessible
  • Verify firewall/proxy settings

2. "Failed to get PR threads: 401 Unauthorized"

  • Enable "Allow scripts to access the OAuth token" in pipeline settings
  • Grant "Contribute to pull requests" permission to Build Service

3. "GitHub Copilot command failed"

  • Verify GITHUB_TOKEN is valid and has copilot scope
  • Check GitHub Copilot subscription is active
  • Ensure token is not expired

4. "No file changes detected" but changes were expected

  • Verify Copilot command actually modified files
  • Review Copilot CLI output in logs

5. AI commands processed multiple times

  • This should no longer happen in v0.1.9+ (closed threads are skipped)
  • Ensure you're using the latest version of the task

Security Considerations

  • 🔒 GitHub Token: Store as a secret variable, never commit to source code
  • 🔒 OAuth Token: Only enable when necessary, limit repository permissions
  • 🔒 Code Review: Always review AI-generated changes before merging

Version History

  • 0.2.2 (2025-01-24): Fix ANSI escape codes in Copilot CLI output - PR comments now display clean text without terminal formatting characters (e.g., [32m, [39m)
  • 0.2.1: Fix duplicate PR threads processing logic - removed redundant code that caused "400 Bad Request" errors in branch builds
  • 0.2.0: Support non-PR context (branch builds) - task now works in both PR and regular branch pipelines
  • 0.1.9: Skip closed threads to prevent duplicate processing
  • 0.1.8: Add thread reply and auto-close functionality
  • 0.1.7: Add smart git status checking
  • 0.1.6: Switch to GitHub Copilot CLI for AI processing
  • 0.1.5: Add copilotPrompt input field
  • 0.1.4: Add GitHub Token support
  • 0.1.3: Add pre-commands execution support
  • 0.1.0: Initial release

License

MIT


正體中文

Azure DevOps Pipeline 任務,整合 GitHub Copilot CLI 實現 AI 驅動的程式碼生成。支援 PR 上下文(處理評論中的 AI 指令)和分支建置(執行自訂 Copilot 提示)。自動提交並推送變更。

功能特色

  • 🤖 AI 驅動的程式碼生成: 整合 GitHub Copilot CLI 處理自然語言指令
  • 💬 PR 評論指令: 在 Pull Request 中評論 AI: <您的需求> 即可執行 AI 指令
  • 🔄 自動 Git 操作: 將變更自動提交並推送回 PR 源分支
  • 📝 討論串管理: 在原始評論討論串中回覆並自動關閉已處理的討論串
  • ⚙️ 前置指令執行: 在任務執行前運行自訂 shell 指令
  • 🎯 自訂 Copilot 提示: 在任務啟動時執行一次性 Copilot 指令
  • 🔒 智慧變更偵測: 僅在偵測到實際檔案變更時才提交並推送

前置需求

1. GitHub Copilot CLI 存取權限

確保您擁有有效的 GitHub Copilot 訂閱並可存取 GitHub Copilot CLI。此任務會自動全域安裝 @github/copilot npm 套件。

2. GitHub Token (必要)

您需要 GitHub Personal Access Token (PAT) 才能使用 GitHub Copilot CLI:

  1. 前往 GitHub Settings → Developer settings → Personal access tokens → Tokens (classic)
  2. 產生一個具有 copilot 範圍的新 token
  3. 將 token 儲存在 Azure DevOps 中:
    • 前往 Pipelines → Library → Secure files/Variable groups
    • 建立變數群組或新增至 pipeline 變數
    • 新增名為 GITHUB_TOKEN 的密碼變數

3. Azure DevOps 權限

啟用 OAuth Token 存取

在您的 pipeline YAML 中,必須啟用腳本存取 OAuth token:

steps:
  - checkout: self
    persistCredentials: true
    fetchDepth: 0

此外,確保 Build Service 具有適當的權限:

  1. 前往 專案設定 → 存放庫 → 選擇您的存放庫
  2. 前往 安全性 分頁
  3. 找到 [您的專案] Build Service ([您的組織]) 使用者
  4. 授予以下權限:
    • ✅ 參與: 允許
    • ✅ 參與提取要求: 允許
    • ✅ 建立分支: 允許
    • ✅ 讀取: 允許

在 Pipeline 設定中啟用 OAuth Token

  1. 前往您的 pipeline
  2. 點擊 編輯 → ... (更多動作) → 觸發程序
  3. 前往 YAML 分頁 → 取得來源
  4. 啟用: ☑️ 允許指令碼存取 OAuth 權杖

使用方式

支援的上下文

此任務可在兩種不同的上下文中運作:

1. Pull Request (PR) 上下文 - 完整功能 ✅

  • ✅ 前置指令執行
  • ✅ GitHub Copilot CLI 安裝
  • ✅ 自訂 copilotPrompt 執行
  • ✅ 處理 PR 評論中的 AI 指令 (例如: AI: 修正錯誤)
  • ✅ 討論串回覆和自動關閉
  • ✅ 提交並推送

使用時機: 在 PR pipeline 中包含此任務,透過 PR 評論啟用 AI 驅動的程式碼修改。

2. 分支建置上下文 - 有限功能 ⚙️

  • ✅ 前置指令執行
  • ✅ GitHub Copilot CLI 安裝
  • ✅ 自訂 copilotPrompt 執行
  • ❌ 處理 PR 評論中的 AI 指令 (無可用的 PR)
  • ✅ 提交並推送

使用時機: 在分支建置(例如: main, develop)中透過 copilotPrompt 參數執行一次性 Copilot 任務。


基本 Pipeline YAML (PR 上下文)

trigger:
  - main

pr:
  - main
  - develop

pool:
  vmImage: 'ubuntu-latest'

variables:
  - group: github-secrets  # 包含 GITHUB_TOKEN 的變數群組

steps:
  - checkout: self
    persistCredentials: true
    fetchDepth: 0

  - task: ADOCodingAgent@0
    displayName: "ADO Coding Agent"
    inputs:
      githubToken: $(GITHUB_TOKEN)  # GitHub Copilot CLI 必要
      commitMessage: "chore: AI auto-fix for PR"
      dryRun: false

使用前置指令

  - task: ADOCodingAgent@0
    displayName: "ADO Coding Agent"
    inputs:
      githubToken: $(GITHUB_TOKEN)
      preCommands: |
        npm install
        npm run build
      failOnPreCmdError: true
      commitMessage: "feat: AI-generated changes"

使用自訂 Copilot 提示

  - task: ADOCodingAgent@0
    displayName: "ADO Coding Agent"
    inputs:
      githubToken: $(GITHUB_TOKEN)
      copilotPrompt: |
        Review all TypeScript files and add JSDoc comments
        to exported functions that are missing documentation
      commitMessage: "docs: Add JSDoc comments"

分支建置 (非 PR 上下文)

在一般分支建置中執行自動化的 Copilot 任務:

trigger:
  - main
  - develop

pool:
  vmImage: 'ubuntu-latest'

variables:
  - group: github-secrets

steps:
  - checkout: self
    persistCredentials: true
    fetchDepth: 0

  - task: ADOCodingAgent@0
    displayName: "Automated Code Quality Check"
    inputs:
      githubToken: $(GITHUB_TOKEN)
      copilotPrompt: |
        Review all code files and fix any linting errors,
        add missing error handling, and ensure code follows
        project coding standards
      commitMessage: "chore: Automated code quality improvements"
      dryRun: false

注意: 在分支建置中,PR 評論處理會自動跳過。僅執行 copilotPrompt 和 preCommands。


在 PR 評論中使用 AI 指令

只需在 Pull Request 中新增以 AI: 開頭的評論:

範例 1: 新增功能

AI: Create a new function in src/utils.js that validates email addresses using regex

範例 2: 修正錯誤

AI: Fix the null pointer exception in the getUserProfile function in src/auth.ts

範例 3: 重構程式碼

AI: Refactor the calculateTotal function in src/cart.js to use reduce instead of forEach

範例 4: 新增測試

AI: Add unit tests for the loginUser function in tests/auth.test.js

此任務將:

  1. ✅ 偵測 PR 評論中的 AI 指令 (僅限開啟/啟用的討論串)
  2. ✅ 使用 GitHub Copilot CLI 執行指令
  3. ✅ 提交並推送任何檔案變更
  4. ✅ 在相同的評論討論串中回覆結果
  5. ✅ 處理完成後自動關閉討論串

任務參數

必要參數

githubToken (string) ✅ 必要

用於 Copilot CLI 認證的 GitHub Personal Access Token

  • 用途: 向 GitHub Copilot 服務進行認證以啟用 AI 驅動的程式碼生成
  • 如何取得: 在 GitHub Settings → Developer settings → Personal access tokens 建立 PAT
  • 必要範圍: copilot (GitHub Copilot 讀取權限)
  • 儲存: 儲存為 Azure DevOps 變數群組或 Pipeline 變數中的密碼變數
  • 使用: githubToken: $(GITHUB_TOKEN)
  • 安全性: 絕不將此 token 提交至原始碼;始終使用 pipeline 變數

選用參數

commitMessage (string)

Git commit 訊息範本

  • 預設值: AI: auto-commit by ADO Coding Agent
  • 用途: 自訂任務所做變更的 commit 訊息
  • 範本變數: PR 編號會自動附加為 #${prId}
  • 範例:
    • feat: AI-generated improvements
    • fix: AI-powered bug fixes
    • docs: AI documentation updates
  • 最佳實踐: 遵循 conventional commits 格式以獲得更好的 changelog 生成

dryRun (boolean)

測試模式 - 在本地提交但不推送至遠端

  • 預設值: false
  • 用途: 測試任務行為而不影響遠端存放庫
  • 啟用時:
    • ✅ 處理所有 AI 指令
    • ✅ 在本地修改檔案
    • ✅ 變更提交至本地 git
    • ❌ 不推送至遠端分支
    • ✅ 在 PR 中發布評論指示試運行模式
  • 使用情境:
    • 測試任務設定
    • 驗證 AI 指令行為
    • 除錯而不影響正式環境程式碼

preCommands (multiline)

在主要任務邏輯之前執行的 Shell 指令

  • 預設值: 無
  • 用途: 在處理 AI 請求之前執行設置、建置或驗證指令
  • 格式: 每行一個指令,或逗號分隔
  • Shell 偵測: 如果可用會自動使用 bash,否則退回系統 shell (Windows 上的 PowerShell/cmd)
  • 範例:
    preCommands: |
      npm install
      npm run build
      npm test
    
    或:
    preCommands: 'npm install, npm run lint'
    
  • 常見使用情境:
    • 安裝相依套件: npm install, pip install -r requirements.txt
    • 執行建置: npm run build, dotnet build
    • 執行測試: npm test, pytest
    • 環境設定: export NODE_ENV=production
  • 環境變數替代方案: 也可以使用 PRE_COMMANDS 環境變數

failOnPreCmdError (boolean)

任何前置指令失敗時整個任務失敗

  • 預設值: false
  • 用途: 控制前置指令遇到錯誤時的任務行為
  • 當為 false (預設):
    • 前置指令失敗會記錄為警告
    • 任務繼續執行
    • 適用於非關鍵的設置步驟
  • 當為 true:
    • 第一個前置指令失敗就停止任務執行
    • 任務標記為失敗
    • 不處理 AI 指令
    • 適用於關鍵相依項或建置
  • 結束代碼偵測: 監控指令結束代碼 (0 = 成功, 非零 = 失敗)
  • 環境變數替代方案: 也可以使用 FAIL_ON_PRECMD_ERROR=1 環境變數

copilotPrompt (multiline)

任務啟動時執行的一次性 GitHub Copilot CLI 提示

  • 預設值: 無
  • 用途: 在處理 PR 評論之前執行單一 AI 任務
  • 執行時機: 在 git 初始化之後、處理 PR 評論中的 AI 指令之前執行
  • 格式: 支援自然語言指令的多行文字
  • 檔案變更追蹤: 所有變更都會被追蹤並包含在最終 commit 中
  • 範例:
    copilotPrompt: |
      Review all TypeScript files and add JSDoc comments
      to exported functions that are missing documentation
    
    copilotPrompt: |
      Find all TODO comments in the codebase and create
      corresponding GitHub issues
    
  • 使用情境:
    • 自動化程式碼品質改進
    • 文件生成
    • 跨檔案的一致性格式化
    • 重構任務
  • 與 PR 評論的差異:
    • PR 評論 (AI: ...): 互動式,每個評論單獨處理並回覆討論串
    • copilotPrompt: 任務啟動時一次性執行,變更包含在主要 commit 中

運作原理

執行流程

1. 執行前置指令 (如有指定)
   ↓
2. 全域安裝 GitHub Copilot CLI
   ↓
3. 設定 GITHUB_TOKEN 環境變數
   ↓
4. 初始化 Git (fetch, checkout PR 分支)
   ↓
5. 設定 Git 使用者身分
   ↓
6. 執行自訂 Copilot 提示 (如有指定)
   ↓
7. 取得所有 PR 評論討論串
   ↓
8. 處理 AI 指令 (跳過已關閉的討論串)
   ↓
9. 檢查檔案變更
   ↓
10. 提交並推送 (如偵測到變更)
    ↓
11. 在 PR 中回覆結果

討論串管理

  • 啟用的討論串: 處理開啟/啟用討論串中的 AI 指令
  • 已關閉的討論串: 自動跳過以防止重複處理
  • 自動關閉: 處理完成後,討論串會自動關閉
  • 討論串回覆: 回應會出現在原始評論討論串中 (而非新討論串)

進階設定

環境變數

您也可以使用環境變數設定任務:

  - task: ADOCodingAgent@0
    env:
      GITHUB_TOKEN: $(GITHUB_TOKEN)
      PRE_COMMANDS: 'npm install, npm test'
      FAIL_ON_PRECMD_ERROR: '1'

前置指令使用 Bash

此任務會自動偵測 bash 是否可用並用於前置指令。在沒有 bash 的 Windows agent 上,會退回使用系統 shell (PowerShell/cmd)。

試運行模式

在不推送變更的情況下測試任務:

  - task: ADOCodingAgent@0
    inputs:
      githubToken: $(GITHUB_TOKEN)
      dryRun: true  # 不推送,僅本地提交

疑難排解

常見問題

1. "Failed to install @github/copilot"

  • 確保 build agent 具有網際網路存取權
  • 檢查 npm 是否已安裝且可存取
  • 驗證防火牆/代理伺服器設定

2. "Failed to get PR threads: 401 Unauthorized"

  • 在 pipeline 設定中啟用「允許指令碼存取 OAuth 權杖」
  • 授予 Build Service「參與提取要求」權限

3. "GitHub Copilot command failed"

  • 驗證 GITHUB_TOKEN 有效且具有 copilot 範圍
  • 檢查 GitHub Copilot 訂閱是否啟用
  • 確保 token 未過期

4. "No file changes detected" 但預期有變更

  • 驗證 Copilot 指令確實修改了檔案
  • 檢視日誌中的 Copilot CLI 輸出

5. AI 指令被處理多次

  • 在 v0.1.9+ 版本中此問題已修正 (已關閉的討論串會被跳過)
  • 確保您使用的是最新版本的任務

安全性考量

  • 🔒 GitHub Token: 儲存為密碼變數,切勿提交至原始碼
  • 🔒 OAuth Token: 僅在必要時啟用,限制存放庫權限
  • 🔒 程式碼審查: 合併前務必審查 AI 產生的變更

版本歷史

  • 0.2.2 (2025-01-24): 修正 Copilot CLI 輸出中的 ANSI 跳脫碼 - PR 評論現在顯示乾淨的文字,不再有終端格式化字元 (例如: [32m, [39m)
  • 0.2.1: 修正重複的 PR 討論串處理邏輯 - 移除在分支建置中造成「400 Bad Request」錯誤的冗餘程式碼
  • 0.2.0: 支援非 PR 上下文 (分支建置) - 任務現在可在 PR 和一般分支 pipeline 中運作
  • 0.1.9: 跳過已關閉的討論串以防止重複處理
  • 0.1.8: 新增討論串回覆和自動關閉功能
  • 0.1.7: 新增智慧 git 狀態檢查
  • 0.1.6: 切換至 GitHub Copilot CLI 進行 AI 處理
  • 0.1.5: 新增 copilotPrompt 輸入欄位
  • 0.1.4: 新增 GitHub Token 支援
  • 0.1.3: 新增前置指令執行支援
  • 0.1.0: 初始版本

授權

MIT


日本語

GitHub Copilot CLIを統合したAI駆動のコード生成を実現するAzure DevOps Pipelineタスク。PRコンテキスト(コメントからのAIコマンド処理)とブランチビルド(カスタムCopilotプロンプトの実行)の両方で動作します。変更を自動的にコミットしてプッシュします。

機能

  • 🤖 AI駆動のコード生成: GitHub Copilot CLIと統合し、自然言語コマンドを処理
  • 💬 PRコメントコマンド: プルリクエストで AI: <あなたのリクエスト> とコメントしてAIコマンドを実行
  • 🔄 自動Git操作: 変更を自動的にPRソースブランチにコミット&プッシュ
  • 📝 スレッド管理: 元のコメントスレッドで返信し、処理済みスレッドを自動クローズ
  • ⚙️ 事前コマンド実行: タスク実行前にカスタムシェルコマンドを実行
  • 🎯 カスタムCopilotプロンプト: タスク起動時に1回限りのCopilotコマンドを実行
  • 🔒 スマート変更検出: 実際のファイル変更が検出された場合のみコミット&プッシュ

前提条件

1. GitHub Copilot CLIアクセス

有効なGitHub Copilotサブスクリプションがあり、GitHub Copilot CLIにアクセスできることを確認してください。タスクは @github/copilot npmパッケージを自動的にグローバルインストールします。

2. GitHubトークン (必須)

GitHub Copilot CLIを使用するには、GitHub Personal Access Token (PAT)が必要です:

  1. GitHub Settings → Developer settings → Personal access tokens → Tokens (classic) に移動
  2. copilot スコープを持つ新しいトークンを生成
  3. Azure DevOpsにトークンを保存:
    • Pipelines → Library → Secure files/Variable groups に移動
    • 変数グループを作成するか、パイプライン変数に追加
    • GITHUB_TOKEN という名前のシークレット変数を追加

3. Azure DevOps権限

OAuthトークンアクセスを有効化

パイプラインYAMLで、スクリプトがOAuthトークンにアクセスできるようにする必要があります:

steps:
  - checkout: self
    persistCredentials: true
    fetchDepth: 0

さらに、Build Serviceに適切な権限があることを確認してください:

  1. プロジェクト設定 → リポジトリ → リポジトリを選択
  2. セキュリティ タブに移動
  3. [プロジェクト名] Build Service ([組織名]) ユーザーを見つける
  4. 以下の権限を付与:
    • ✅ 投稿: 許可
    • ✅ プルリクエストへの投稿: 許可
    • ✅ ブランチの作成: 許可
    • ✅ 読み取り: 許可

パイプライン設定でOAuthトークンを有効化

  1. パイプラインに移動
  2. 編集 → ... (その他のアクション) → トリガー をクリック
  3. YAML タブ → ソースの取得 に移動
  4. 有効化: ☑️ スクリプトがOAuthトークンにアクセスすることを許可

使用方法

サポートされるコンテキスト

このタスクは2つの異なるコンテキストで動作します:

1. プルリクエスト (PR) コンテキスト - フル機能 ✅

  • ✅ 事前コマンド実行
  • ✅ GitHub Copilot CLI インストール
  • ✅ カスタム copilotPrompt 実行
  • ✅ PRコメントからのAIコマンド処理 (例: AI: バグを修正)
  • ✅ スレッド返信と自動クローズ
  • ✅ コミット & プッシュ

使用タイミング: PRパイプラインにこのタスクを含めて、PRコメント経由でAI駆動のコード変更を有効にします。

2. ブランチビルドコンテキスト - 限定機能 ⚙️

  • ✅ 事前コマンド実行
  • ✅ GitHub Copilot CLI インストール
  • ✅ カスタム copilotPrompt 実行
  • ❌ PRコメントからのAIコマンド処理 (PR利用不可)
  • ✅ コミット & プッシュ

使用タイミング: ブランチビルド (例: main, develop) で copilotPrompt パラメータを使用して1回限りのCopilotタスクを実行します。


基本的なパイプラインYAML (PRコンテキスト)

trigger:
  - main

pr:
  - main
  - develop

pool:
  vmImage: 'ubuntu-latest'

variables:
  - group: github-secrets  # GITHUB_TOKENを含む変数グループ

steps:
  - checkout: self
    persistCredentials: true
    fetchDepth: 0

  - task: ADOCodingAgent@0
    displayName: "ADO Coding Agent"
    inputs:
      githubToken: $(GITHUB_TOKEN)  # GitHub Copilot CLIに必須
      commitMessage: "chore: AI auto-fix for PR"
      dryRun: false

事前コマンド付き

  - task: ADOCodingAgent@0
    displayName: "ADO Coding Agent"
    inputs:
      githubToken: $(GITHUB_TOKEN)
      preCommands: |
        npm install
        npm run build
      failOnPreCmdError: true
      commitMessage: "feat: AI-generated changes"

カスタムCopilotプロンプト付き

  - task: ADOCodingAgent@0
    displayName: "ADO Coding Agent"
    inputs:
      githubToken: $(GITHUB_TOKEN)
      copilotPrompt: |
        Review all TypeScript files and add JSDoc comments
        to exported functions that are missing documentation
      commitMessage: "docs: Add JSDoc comments"

ブランチビルド (非PRコンテキスト)

通常のブランチビルドで自動化されたCopilotタスクを実行:

trigger:
  - main
  - develop

pool:
  vmImage: 'ubuntu-latest'

variables:
  - group: github-secrets

steps:
  - checkout: self
    persistCredentials: true
    fetchDepth: 0

  - task: ADOCodingAgent@0
    displayName: "Automated Code Quality Check"
    inputs:
      githubToken: $(GITHUB_TOKEN)
      copilotPrompt: |
        Review all code files and fix any linting errors,
        add missing error handling, and ensure code follows
        project coding standards
      commitMessage: "chore: Automated code quality improvements"
      dryRun: false

注意: ブランチビルドでは、PRコメント処理は自動的にスキップされます。copilotPrompt と preCommands のみが実行されます。


PRコメントでAIコマンドを使用

プルリクエストで AI: で始まるコメントを追加するだけです:

例1: 新機能の追加

AI: Create a new function in src/utils.js that validates email addresses using regex

例2: バグ修正

AI: Fix the null pointer exception in the getUserProfile function in src/auth.ts

例3: リファクタリング

AI: Refactor the calculateTotal function in src/cart.js to use reduce instead of forEach

例4: テスト追加

AI: Add unit tests for the loginUser function in tests/auth.test.js

タスクは以下を実行します:

  1. ✅ PRコメント内のAIコマンドを検出 (アクティブ/オープンスレッドのみ)
  2. ✅ GitHub Copilot CLIを使用してコマンドを実行
  3. ✅ ファイル変更をコミット&プッシュ
  4. ✅ 同じコメントスレッドで結果を返信
  5. ✅ 処理後にスレッドを自動的にクローズ

タスクパラメータ

必須パラメータ

githubToken (string) ✅ 必須

GitHub Copilot CLI認証用のGitHub Personal Access Token

  • 目的: GitHub CopilotサービスでAI駆動のコード生成を可能にするための認証
  • 取得方法: GitHub Settings → Developer settings → Personal access tokensでPATを作成
  • 必要なスコープ: copilot (GitHub Copilot読み取りアクセス)
  • 保存: Azure DevOps Variable GroupsまたはPipeline Variablesのシークレット変数として保存
  • 使用: githubToken: $(GITHUB_TOKEN)
  • セキュリティ: このトークンをソースコードにコミットしないでください。常にパイプライン変数を使用してください

オプションパラメータ

commitMessage (string)

Gitコミットメッセージテンプレート

  • デフォルト: AI: auto-commit by ADO Coding Agent
  • 目的: タスクによって行われた変更のコミットメッセージをカスタマイズ
  • テンプレート変数: PR番号は自動的に #${prId} として追加されます
  • 例:
    • feat: AI-generated improvements
    • fix: AI-powered bug fixes
    • docs: AI documentation updates
  • ベストプラクティス: changelog生成のためにconventional commitsフォーマットに従ってください

dryRun (boolean)

テストモード - ローカルでコミットしてリモートにプッシュしない

  • デフォルト: false
  • 目的: リモートリポジトリに影響を与えずにタスクの動作をテスト
  • 有効な場合:
    • ✅ すべてのAIコマンドが処理されます
    • ✅ ファイルがローカルで変更されます
    • ✅ 変更がローカルgitにコミットされます
    • ❌ リモートブランチへのプッシュなし
    • ✅ ドライランモードを示すコメントがPRに投稿されます
  • ユースケース:
    • タスク設定のテスト
    • AIコマンド動作の検証
    • 本番コードに影響を与えずにデバッグ

preCommands (multiline)

メインタスクロジックの前に実行されるシェルコマンド

  • デフォルト: なし
  • 目的: AIリクエストを処理する前にセットアップ、ビルド、または検証コマンドを実行
  • フォーマット: 1行に1コマンド、またはカンマ区切り
  • シェル検出: 利用可能な場合は自動的に bash を使用し、そうでない場合はシステムシェル (WindowsのPowerShell/cmd) にフォールバック
  • 例:
    preCommands: |
      npm install
      npm run build
      npm test
    
    または:
    preCommands: 'npm install, npm run lint'
    
  • 一般的なユースケース:
    • 依存関係のインストール: npm install, pip install -r requirements.txt
    • ビルドの実行: npm run build, dotnet build
    • テストの実行: npm test, pytest
    • 環境設定: export NODE_ENV=production
  • 環境変数の代替: PRE_COMMANDS 環境変数も使用できます

failOnPreCmdError (boolean)

事前コマンドが失敗した場合にタスク全体を失敗させる

  • デフォルト: false
  • 目的: 事前コマンドでエラーが発生したときのタスク動作を制御
  • false の場合 (デフォルト):
    • 事前コマンドの失敗は警告としてログに記録されます
    • タスクは実行を継続します
    • 重要でないセットアップステップに有用
  • true の場合:
    • 最初の事前コマンド失敗でタスク実行が停止します
    • タスクは失敗としてマークされます
    • AIコマンドは処理されません
    • 重要な依存関係やビルドに有用
  • 終了コード検出: コマンドの終了コードを監視します (0 = 成功、非ゼロ = 失敗)
  • 環境変数の代替: FAIL_ON_PRECMD_ERROR=1 環境変数も使用できます

copilotPrompt (multiline)

タスク起動時に実行される1回限りのGitHub Copilot CLIプロンプト

  • デフォルト: なし
  • 目的: PRコメントを処理する前に単一のAIタスクを実行
  • 実行タイミング: git初期化後、PRコメントからのAIコマンド処理前に実行
  • フォーマット: 自然言語指示をサポートする複数行テキスト
  • ファイル変更追跡: すべての変更が追跡され、最終コミットに含まれます
  • 例:
    copilotPrompt: |
      Review all TypeScript files and add JSDoc comments
      to exported functions that are missing documentation
    
    copilotPrompt: |
      Find all TODO comments in the codebase and create
      corresponding GitHub issues
    
  • ユースケース:
    • 自動化されたコード品質の改善
    • ドキュメント生成
    • ファイル全体での一貫したフォーマット
    • リファクタリングタスク
  • PRコメントとの違い:
    • PRコメント (AI: ...): インタラクティブ、コメントごとに処理してスレッドに返信
    • copilotPrompt: タスク起動時に1回実行、変更はメインコミットに含まれます

動作原理

実行フロー

1. 事前コマンドを実行 (指定されている場合)
   ↓
2. GitHub Copilot CLIをグローバルインストール
   ↓
3. GITHUB_TOKEN環境変数を設定
   ↓
4. Gitを初期化 (fetch、PRブランチをcheckout)
   ↓
5. Gitユーザー識別情報を設定
   ↓
6. カスタムCopilotプロンプトを実行 (指定されている場合)
   ↓
7. すべてのPRコメントスレッドを取得
   ↓
8. AIコマンドを処理 (クローズされたスレッドをスキップ)
   ↓
9. ファイル変更をチェック
   ↓
10. コミット&プッシュ (変更が検出された場合)
    ↓
11. 結果をPRで返信

スレッド管理

  • アクティブスレッド: オープン/アクティブスレッド内のAIコマンドが処理されます
  • クローズされたスレッド: 重複処理を防ぐために自動的にスキップ
  • 自動クローズ: 処理後、スレッドは自動的にクローズ
  • スレッド返信: 応答は元のコメントスレッドに表示されます (新しいスレッドではありません)

高度な設定

環境変数

環境変数を使用してタスクを設定することもできます:

  - task: ADOCodingAgent@0
    env:
      GITHUB_TOKEN: $(GITHUB_TOKEN)
      PRE_COMMANDS: 'npm install, npm test'
      FAIL_ON_PRECMD_ERROR: '1'

事前コマンドでBashを使用

タスクは bash が利用可能かどうかを自動的に検出し、事前コマンドに使用します。bashのないWindowsエージェントでは、システムシェル (PowerShell/cmd) にフォールバックします。

ドライランモード

変更をプッシュせずにタスクをテスト:

  - task: ADOCodingAgent@0
    inputs:
      githubToken: $(GITHUB_TOKEN)
      dryRun: true  # プッシュなし、ローカルコミットのみ

トラブルシューティング

よくある問題

1. "Failed to install @github/copilot"

  • ビルドエージェントがインターネットアクセスを持っていることを確認
  • npmがインストールされ、アクセス可能であることを確認
  • ファイアウォール/プロキシ設定を確認

2. "Failed to get PR threads: 401 Unauthorized"

  • パイプライン設定で「スクリプトがOAuthトークンにアクセスすることを許可」を有効化
  • Build Serviceに「プルリクエストへの投稿」権限を付与

3. "GitHub Copilot command failed"

  • GITHUB_TOKENが有効で copilot スコープを持っていることを確認
  • GitHub Copilotサブスクリプションがアクティブであることを確認
  • トークンが期限切れでないことを確認

4. "No file changes detected" だが変更が期待される

  • Copilotコマンドが実際にファイルを変更したことを確認
  • ログでCopilot CLIの出力を確認

5. AIコマンドが複数回処理される

  • v0.1.9+ではこの問題は修正されています (クローズされたスレッドはスキップされます)
  • タスクの最新バージョンを使用していることを確認

セキュリティに関する考慮事項

  • 🔒 GitHubトークン: シークレット変数として保存し、ソースコードにコミットしないでください
  • 🔒 OAuthトークン: 必要な場合のみ有効化し、リポジトリ権限を制限
  • 🔒 コードレビュー: マージ前にAI生成の変更を必ずレビュー

バージョン履歴

  • 0.2.2 (2025-01-24): Copilot CLI出力のANSIエスケープコードを修正 - PRコメントがターミナル書式文字なしでクリーンなテキストを表示するようになりました (例: [32m, [39m)
  • 0.2.1: 重複するPRスレッド処理ロジックを修正 - ブランチビルドで「400 Bad Request」エラーを引き起こす冗長なコードを削除
  • 0.2.0: 非PRコンテキスト (ブランチビルド) をサポート - タスクがPRと通常のブランチパイプラインの両方で動作するようになりました
  • 0.1.9: 重複処理を防ぐためにクローズされたスレッドをスキップ
  • 0.1.8: スレッド返信と自動クローズ機能を追加
  • 0.1.7: スマートgitステータスチェックを追加
  • 0.1.6: AI処理にGitHub Copilot CLIに切り替え
  • 0.1.5: copilotPrompt入力フィールドを追加
  • 0.1.4: GitHubトークンサポートを追加
  • 0.1.3: 事前コマンド実行サポートを追加
  • 0.1.0: 初回リリース

ライセンス

MIT

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft