地端Azure DevOps Agent整合Proxy的問題集

地端Azure DevOps Agent整合Proxy的問題集

早期因為公司網路架構問題,在地端架設的Azure DevOps Agent一直有個問題,就是我們必須手動進行更新。雖然有寫成指令碼來協助,但不能全自動化,就是覺得麻煩。

近期,架構上有所突破,我們可以採取Proxy連線的方式,來重新設定這些地端的Azure DevOps Agent,但在重新設定之後,碰到一些問題,這在整理起來。

架設地端Azure DevOps Agent整合Proxy

對於架設地端Azure DevOps Agent,官網文件寫的算清楚的了,請自行參考。

如主題所說,我們要整合Proxy,所以需要再參考這一篇 在 Web Proxy 後方執行自我裝載式代理程式

Ubuntu Agent 重設流程:

sudo ./svc.sh stop
sudo ./svc.sh uninstall
./config.sh remove
./config.sh --proxyurl http://yourproxy:port --proxyusername "username" --proxypassword "password"

Windows Agent 重設流程:

.\config remove
.\config --proxyurl 'http://yourproxy:port' --proxyusername 'username' --proxypassword 'password'

以下的設定會進入互動模式,需要一一回答一些組態問題,當然你可以參考文件寫一支 Bash Script 和 PowerShell Script 做出可重覆使用的指令碼。

No Proxy

記得,有 Proxy 組態必須配合 No Proxy 組態。在 在 Web Proxy 後方執行自我裝載式代理程式 的最後一段就可以說明,自己新增一個 .proxybypass 檔案,一般是指定公司內網的IP或網域名稱來進行排除。

Azure DevOps Agent - No Proxy

Azure DevOps Agent Proxy - NuGet restore Failed

來看 Build Error 的錯誤訊息說故事。

##[debug]Processed: ##vso[telemetry.publish area=Packaging;feature=NuGetCommand]{"SYSTEM_TASKINSTANCEID":"3ecfe64b-c730-530d-8b85-fb883d98bfae","SYSTEM_JOBID":"253e5128-1058-5bd4-fdf1-9b556d3207f8","SYSTEM_PLANID":"a848b8d2-0f2a-41d9-ac89-b6cbbec98394","SYSTEM_COLLECTIONID":"55a18ebc-db1a-48d3-ba07-636da553e73e","AGENT_ID":"271","AGENT_MACHINENAME":"xxx","AGENT_NAME":"xxx-build1","AGENT_JOBSTATUS":"Succeeded","AGENT_OS":"Windows_NT","AGENT_VERSION":"3.225.0","BUILD_BUILDID":"93667","BUILD_BUILDNUMBER":"20230907.27","BUILD_BUILDURI":"vstfs:///Build/Build/93667","BUILD_CONTAINERID":"35938428","BUILD_DEFINITIONNAME":"kkk","BUILD_DEFINITIONVERSION":"117","BUILD_REASON":"Manual","BUILD_REPOSITORY_CLEAN":"False","BUILD_REPOSITORY_GIT_SUBMODULECHECKOUT":"False","BUILD_REPOSITORY_NAME":"ppp.kkk","BUILD_REPOSITORY_PROVIDER":"TfsGit","BUILD_SOURCEVERSION":"346930a46064968e75c21f1a27d4dc1e8f696ede","exitCode":1}
##[debug]rm -rf D:\Agent\_work\672\Nuget\tempNuGet_93667.config
##[debug]removing file D:\Agent\_work\672\Nuget\tempNuGet_93667.config
##[error]The nuget command failed with exit code(1) and error(Errors in packages.config projects
    Unable to find version '1.6.0' of package 'Component.Telemetry'.
      C:\Users\vvv\.nuget\packages\: Package 'Component.Telemetry.1.6.0' is not found on source 'C:\Users\vvv\.nuget\packages\'.
      https://pkgs.dev.azure.com/kkk/cd6c8655-0b81-4864-b5d0-bd378010b78b/_packaging/8ea07900-0090-48b8-abd2-e59d9f0dbb97/nuget/v3/index.json: Could not find a part of the path 'D:\Agent\_work\_temp\NuGetPluginsCache\1a0a22c4eb73d73f54f7aa73cf481bd6c7c36c71$CredentialProvider.Microsoft.exe\https_pkgs.dev.azure.com_KKK_cd6c8655-0b81-4864-b5d0-bd378010b78b_packaging_8ea07900-0090-48b8-abd2-e59d9f0dbb97_nuget_v3_index.json.dat-new'.)
##[debug]Processed: ##vso[task.issue type=error;]The nuget command failed with exit code(1) and error(Errors in packages.config projects
    Unable to find version '1.6.0' of package 'Component.Telemetry'.
      C:\Users\vvv\.nuget\packages\: Package 'Component.Telemetry.1.6.0' is not found on source 'C:\Users\vvv\.nuget\packages\'.
      https://pkgs.dev.azure.com/KKK/cd6c8655-0b81-4864-b5d0-bd378010b78b/_packaging/8ea07900-0090-48b8-abd2-e59d9f0dbb97/nuget/v3/index.json: Could not find a part of the path 'D:\Agent\_work\_temp\NuGetPluginsCache\1a0a22c4eb73d73f54f7aa73cf481bd6c7c36c71$CredentialProvider.Microsoft.exe\https_pkgs.dev.azure.com_KKK_cd6c8655-0b81-4864-b5d0-bd378010b78b_packaging_8ea07900-0090-48b8-abd2-e59d9f0dbb97_nuget_v3_index.json.dat-new'.)
##[debug]task result: Failed
##[error]Packages failed to restore
##[debug]Processed: ##vso[task.issue type=error;]Packages failed to restore
##[debug]Processed: ##vso[task.complete result=Failed;]Packages failed to restore

某個專案,在 Agent 設定 Proxy 之後,建置程中的 NuGet 還原會失敗。比對其他能正常建置的專案後最後找到原因:

NuGet Restore failed

此問題專案採用 NuGet Task 裡的 Feed(s) | select here 選項,這個選項的 nuget.config 是在建置過程由 Agent 自動化產生的。它是造成導入 Proxy 之後 NuGet Task 無法還原的主因。因此只需在專案內新增 nuget.config 組態好對應的 Source 相關資訊,如上圖指定好專案內的 nuget.config 來源就能決解

Azure DevOps Agent Proxy - TFS 未授權存取

來看錯誤訊息說故事。

Prepending Path environment variable with directory containing 'tf.exe'.
Setting environment variable TFVC_BUILDAGENT_POLICYPATH
Querying workspace information.
##[warning]Exit code 100 returned from process: file name 'tf', arguments '@tfs_cmd_ae8f6c72-4e0e-4f63-be0b-88f13a56b1ee.txt'.
Sleeping for 200 ms before starting 1/3 retry
##[warning]Exit code 100 returned from process: file name 'tf', arguments '@tfs_cmd_bf005b7b-975f-4828-9aab-602830706a7e.txt'.
Sleeping for 1000 ms before starting 2/3 retry
##[warning]Exit code 100 returned from process: file name 'tf', arguments '@tfs_cmd_5d1318e3-512a-438f-b671-a4d83f8b7ebe.txt'.
Sleeping for 5000 ms before starting 3/3 retry

TF30063: You are not authorized to access https://dev.azure.com/KKK.
##[error]Exit code 100 returned from process: file name 'tf', arguments '@tfs_cmd_7f392c14-12f8-4cb1-a5ca-9e4ba44f20db.txt'.

這是個 TFS 的專案。請教專業的同事,得到一個網路查不到的解法:

  1. 重設Agent,進行組態還原
  2. Agent\externals 將整個 tf 目錄複製出來
  3. 觸發 Agent 執行,造成錯誤
  4. 將整個 tf 目錄複製回去 Agent\externals
  5. 再觸發 Agent 執行,就能正常執行

經過仔細比對,發現一些有趣差異,當第 3 步造成錯誤後,tf 目錄下的會多一支 tf.exe.config.restore,而 tf.exe.config 會被異動加上以下 Proxy 組態。

<system.net>
  <defaultProxy useDefaultCredentials="True">
    <proxy proxyaddress="http://yourproxy:port" />
  </defaultProxy>
</system.net>

我有手動移除 tf.exe.config 裡這一段 Proxy 組態,但沒效果。但整個目錄複製出來,再覆寫回去,同事說就能回到 TFS 可正常存取的狀態。但 tf 目錄下除了 tf.exe.config 都是 DLL 檔案。感覺如果當初我是用 tf.exe.config.restore 直接貼過去 tf.exe.config 或許可行。

TFS 的 No Proxy

在不斷驗證中,最後一組 Agent 在重設後,發生一件好玩的事,我設完 Agent,本來 TFS 這裡正準備走同事提供的路,結果我好奇心的驅使下,我又去按了一次 Run Pipeline。在沒有任何修改下,整個建置沒有發生錯誤就綠燈了。比對和之前設定的步驟,發現有些明顯步驟上的差異,這一次我是先放.proxybypass進去,而且沒有重啟 agent。 也就是說,平常設定好 Agent 之後,我把 .proxybypass 放入 Agent 的目錄下之後,因為怕 Agent 沒吃到 .proxybypass 的組態,因此會習慣性的去重啟 Agent 服務。

不確定是不是還沒重啟 Agent 服務加上 .proxybypass 的組態關係,造成目前這組 Agent 除了加入 .proxybypass 之外,沒再做其他動作,運作起來反正一切正常。只是我已經沒有測試環境了,無法再驗證,先留個筆記記錄,等未來Agent更新或主機維護,造成Agent重新啟動時,看是否有再發生問題,如果發生問題,最少方向是明確的,可以快速再次驗證。

沒有留言:

張貼留言

感謝您的留言,如果我的文章你喜歡或對你有幫助,按個「讚」或「分享」它,我會很高興的。