2026年12月2日

GitLab串接Jira實現全自動開發:Duo Agent一鍵將工單轉化為MR代碼

GitLab串接Jira實現全自動開發:Duo Agent一鍵將工單轉化為MR代碼

現時不少香港企業與開發團隊均採用「Jira規劃、GitLab出貨」的敏捷模式。然而,即使團隊已引入AI輔助工具,日常流程依然要在Jira查閱Ticket內容、手動複製要求至AI Agent編寫代碼,最後再把產生的Merge Request(MR)手動回貼到Jira工單中。為了解決這項痛點,GitLab詳細示範了如何利用GitLab Duo Agent Platform消除繁瑣交接,配合Model Context Protocol(MCP)將Jira工單自動化轉化為GitLab MR。

整合事前準備與權限要求

要啟用這套自動化流程,團隊需具備相應的環境配置與權限:

  • GitLab版本:GitLab.com上的GitLab Premium或Ultimate訂閱,並在頂層群組啟用GitLab Duo Agent Platform、「Allow foundational flows」以及Developer功能;專案層級亦需在「Settings > General > GitLab Duo」開啟「Allow foundational flows」(可參考Developer Flow先決條件)。
  • 運算資源:專案必須配置可用的CI Runner。
  • MCP實驗功能:頂層群組需在「Settings > GitLab Duo > Change configuration」啟用實驗性及Beta功能,方可在AI Catalog中取用Atlassian MCP伺服器。
  • 帳號權限:設定階段需擁有專案的Maintainer或Owner角色;後續日常使用只需Developer或以上權限。Jira方面則需具備Jira Cloud專案讀寫權限,以及一次性的Atlassian組織管理員權限,用作信任GitLab為MCP客戶端。
  • API Token:從id.atlassian.com取得Jira API Token,僅供GitLab標準Jira整合使用。

需留意的是,AI Catalog中的Atlassian MCP伺服器目前仍屬實驗性質(Experiment),官方建議先在測試專案中試用,切勿直接投入關鍵生產環境。

步驟一:建立GitLab與Jira標準雙向連結

第一步是設定GitLab既有的Jira整合,過程約需5分鐘,每個專案只需設定一次。此步驟確保代碼庫的Commit或MR只要提及工單編號(例如KAN-123),便會自動在Jira工單留下記錄及留言:

  1. 進入GitLab專案的「Settings > Integrations > Jira issues」。
  2. 勾選「Active」。
  3. Web URL填入Jira站點網址(例如https://your-site.atlassian.net)。
  4. Authentication method選擇Basic authentication,輸入Atlassian電郵與API Token。
  5. 在Trigger項目勾選Commit與Merge request,並啟用Enable comments。
  6. (可選)在Jira issues項目勾選View Jira issues並輸入專案代碼(如KAN),即可在GitLab的「Plan > Jira issues」介面直接檢視工單清單。
  7. 點擊Test settings測試連線,確認無誤後點擊Save changes。

步驟二:建置Jira專屬Custom Agent與MCP授權

設定好標準整合後,便可透過GitLab介面自訂專屬AI Agent,並透過MCP伺服器賦予操作Jira的工具權限。整個設定大約需時10分鐘。

首先,前往admin.atlassian.com進行網域信任設定。進入所屬組織後,在左側選單點擊「Connectors > Atlassian MCP server」,選擇「Add domain」並加入https://gitlab.com/**。此步驟必須具備Atlassian組織管理員權限,否則後續OAuth認證將被Atlassian拒絕。

GitLab's AI > Agents page, with the Agents sidebar item and New agent button highlighted

接著在GitLab專案內進入「AI > Agents > New agent」建立自訂Agent:

  • Display name:Jira
  • Description:Ask about Jira tickets, triage, summarize, comment, and hand work to the Developer flow
  • System prompt:設定提示詞,明確指示Agent擔當Jira助理角色,使用JQL搜尋緊急與被阻擋的任務、將工單內容視為需求而非執行指令、不直接編寫代碼,並在用戶發起/goal指令後負責回報MR進度與連結。
  • MCP servers:勾選「Atlassian」並儲存。
The Jira agent's configuration page in GitLab, showing the Custom type, the system prompt, and the Atlassian MCP server selected

建立後Agent會自動發布至AI Catalog。此時需在AI Catalog中找到該Agent並點擊Enable,為需要使用的專案啟用。最後,團隊成員進入專案的「AI > MCP servers」,找到Atlassian一欄並點擊「Connect」,授權各自的Atlassian帳戶。這項設計確保每位工程師在Jira留下的留言均顯示其個人姓名,而非單一Bot身份。

The project's AI > MCP servers page, with the Atlassian row and its Connect button

步驟三與四:日常對話篩選任務及發起Developer Flow

日常使用時,工程師在GitLab Duo側邊欄點選「Add new chat」,從下拉選單切換至「Jira」Agent,並確認開啟「Agentic」開關。用家可以直接以自然語言提問,例如:Which of my open Jira issues in KAN are High or Highest priority?

Agentic Chat with the Jira agent selected from the agent dropdown, showing the approved Jira tool calls and the resulting table of high-prio

Agent會自動產生JQL查詢(如project = KAN AND assignee = currentUser() AND priority in (High, Highest) AND statusCategory != Done ORDER BY created ASC),經用戶批准後調用Atlassian工具並以表格回覆。工程師可像與同事溝通般持續追問細節,無須切換視窗。

確定目標工單後,可先要求Agent總結需求(如Summarize KAN-123 including the comments. What exactly needs to change?)。確認無誤後,即可透過+ > Goal標籤或直接以/goal指令將任務交接予Developer Flow:

/goal Implement KAN-123: add a /healthz endpoint returning 200 and {"status":"ok"}, with a test. Create a branch named KAN-123-healthz and open a DRAFT merge request. The MR description must start with: Resolves KAN-123 - https://your-site.atlassian.net/browse/KAN-123
The Agentic Chat message box with the Goal label attached and "Implement KAN-123" typed in

系統接收到Goal後,會自動在背景啟動CI Pipeline執行Developer Flow,而非在瀏覽器端運作。AI會分析代碼庫、撰寫程式碼與單元測試、建立新分支並發起Draft MR。小型任務通常在2至5分鐘內即可完成,期間用家可繼續進行其他對話。由於Goal在啟動後擁有Git與GitLab API的寫入權限,發送指令前確認內容就是唯一的把關節點。

代碼審查與日常進階應用

當CI Session顯示Finished後,Draft MR即準備就緒。如同一般團隊協作,AI產生的MR必須經過人工審查,系統絕不會自動合併代碼。當用家在Chat中發送後續訊息時,Jira Agent會自動在對應的Jira工單發布摘要及MR超連結;而步驟一的Jira整合亦會同步更新工單記錄。

除了全自動寫代碼,Jira Agent在日常站會與排程管理上亦能處理多種繁瑣查詢:

  • 回顧進度:輸入「What did the team close this sprint?」,列出上個Sprint完成的任務並按負責人分類。
  • 追蹤滯後工作:輸入「Anything assigned to me that has been In Progress for more than a week?」,於每日站立會議前找出卡關任務。
  • 快速了解討論脈絡:輸入「Summarize the discussion on <KEY> for someone new to it」,自動濃縮冗長留言。
  • 逆向產生工單:輸入「Draft a Jira ticket from merge request !<MR number>」,Agent會閱讀MR內容並起草工單標題、描述及驗收條件,待用家批准後才正式建立。

常見疑難排解(Troubleshooting)

若在設定或運行時遇上問題,可參考以下官方解決方案:

  • AI Catalog未顯示MCP分頁:因未開啟實驗功能,請至「Settings > GitLab Duo」啟用實驗與Beta功能。
  • Atlassian連線失敗或循環跳轉:Atlassian站點未信任GitLab,需於Atlassian Administration將https://gitlab.com/**加入受信任網域。
  • Agent回覆無權限存取Jira:確認是否切換到自訂的Jira Agent而非預設Agent,並檢查「AI > MCP servers」是否顯示為Connected。
  • 找不到/goal指令:對話視窗未在專案頁面開啟,或未於頂層群組啟用Developer及專案層級啟用Allow foundational flows。
  • Session卡在Created狀態:專案缺乏可用的CI Runner,請檢查「Build > Jobs」配置。
  • MR已建立但Jira無留言:檢查步驟一的Enable comments是否勾選,並確保Goal指令中包含「Resolves KEY」字樣。

需提醒團隊的是,每一次執行/goal指令均為完整的Agent運算階段,會消耗GitLab Credits。工程師在發送指令前給予清晰具體的需求描述,方能達到最佳的自動化開發效益。

資料來源:GitLab