使用Azure Pipelines時代理指令碼一直不成功,根據官方提示,可以使用下方的註冊指令碼自動執行代理
實際執行過程中,經常是無法執行完成,仔細閱讀指令碼,發現該指令碼一共做了如下幾步:
1.下載代理 agentZip壓縮包到C盤azagent目錄下
2.解壓縮agent為Agent1(如果存在序號會一次遞增)
3.執行解壓後的agent目錄種的“config.cmd” 啟動配置
4.刪除agentzip包
$ErrorActionPreference="Stop";If(-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent() ).IsInRole( [Security.Principal.WindowsBuiltInRole] “Administrator”)){ throw "Run command in an administrator PowerShell prompt"};If($PSVersionTable.PSVersion -lt (New-Object System.Version("3.0"))){ throw "The minimum version of Windows PowerShell that is required by the script (3.0) does not match the currently running version of Windows PowerShell." };If(-NOT (Test-Path $env:SystemDrive\'azagent')){mkdir $env:SystemDrive\'azagent'}; cd $env:SystemDrive\'azagent'; for($i=; $i -lt ; $i++){$destFolder="A"+$i.ToString();if(-NOT (Test-Path ($destFolder))){mkdir $destFolder;cd $destFolder;break;}}; $agentZip="$PWD\agent.zip";$DefaultProxy=[System.Net.WebRequest]::DefaultWebProxy;$securityProtocol=@();$securityProtocol+=[Net.ServicePointManager]::SecurityProtocol;$securityProtocol+=[Net.SecurityProtocolType]::Tls12;[Net.ServicePointManager]::SecurityProtocol=$securityProtocol;$WebClient=New-Object Net.WebClient; $Uri='https://vstsagentpackage.azureedge.net/agent/2.144.2/vsts-agent-win-x64-2.144.2.zip';if($DefaultProxy -and (-not $DefaultProxy.IsBypassed($Uri))){$WebClient.Proxy= New-Object Net.WebProxy($DefaultProxy.GetProxy($Uri).OriginalString, $True);}; $WebClient.DownloadFile($Uri, $agentZip);Add-Type -AssemblyName System.IO.Compression.FileSystem;[System.IO.Compression.ZipFile]::ExtractToDirectory( $agentZip, "$PWD");.\config.cmd --deploymentgroup --deploymentgroupname "DeployGroup" --agent $env:COMPUTERNAME --runasservice --work '_work' --url 'https://dev.azure.com/TestRepo/' --projectname 'WebDemo'; Remove-Item $agentZip;
由於微軟官網下載很慢導致第一步就卡住,那我們就直接從官網直接下載壓縮包,在指令碼中可以直接看到zip包的下載地址,直接下載該檔案即可。
第二步:手動解壓到C盤azagent目錄下的Agent1資料夾中(目錄可以自由建立,這裡使用的是agent1)
該目錄下存在2個cmd,config.cmd用來執行代理引數的配置,run.cmd負責啟動agent
第三步:配置代理config引數,這裡使用的powshell 需要 .\ 才能執行cmd 喔
.\config
執行完發現部署組並沒有出現該代理,難道配置錯誤,仔細再閱讀原指令碼,發現官方指令碼中 config後面帶了一堆引數,ok 這次全部加上,裡面附帶了所屬部署組和專案名稱等引數
.\config.cmd --deploymentgroup --deploymentgroupname "DeployGroup" --agent $env:COMPUTERNAME --runasservice --work '_work' --url 'https://dev.azure.com/TestRepo/' --projectname 'WebDemo'
由於之前已經配置了一次 需要先刪除原有的配置再執行(執行 .\config.cmd remove即可),然後再執行上面的指令碼即可.
PS C:\azagent\A3> .\config.cmd remove
正在從伺服器刪除代理
輸入 身份驗證型別 (對於 PAT 按 Enter) >
輸入 個人訪問令牌 > ***********************************
正在連線到伺服器...
已成功: 正在從伺服器刪除代理
正在刪除 .credentials
已成功: 正在刪除 .credentials
正在刪除 .agent
已成功: 正在刪除 .agent
PS C:\azagent\A3> .\config.cmd --deploymentgroup --deploymentgroupname "DeployGroup" --agent $env:COMPUTERNAME --runasse
rvice --work '_work' --url 'https://dev.azure.com/TestRepo/' --projectname 'WebDemo' >> 連線: 輸入 身份驗證型別 (對於 PAT 按 Enter) > vwvyzagdtm7nhup
為 身份驗證型別 輸入一個有效值。
輸入 身份驗證型別 (對於 PAT 按 Enter) >
輸入 個人訪問令牌 > ***********************************
正在連線到伺服器... >> 註冊代理: 正在掃描工具功能。
正在連線到伺服器。
輸入 代理的部署組標記? (是/否) (對於 N 按 Enter) >
已成功新增代理
正在測試代理連線。
-- ::26Z: 設定已儲存。
輸入 要用於服務的使用者帳戶 (對於 NT AUTHORITY\SYSTEM 按
將檔案許可權授予“NT AUTHORITY\SYSTEM”。
已成功安裝服務 vstsagent.TestRepo.iZcdeh6xxtihkjZ
已成功設定服務 vstsagent.TestRepo.iZcdeh6xxtihkjZ 的恢
服務 vstsagent.TestRepo.iZcdeh6xxtihkjZ 已成功設定為延
已成功配置服務 vstsagent.TestRepo.iZcdeh6xxtihkjZ
已成功啟動服務 vstsagent.TestRepo.iZcdeh6xxtihkjZ
這次終於看到成功介面了~~~~(>_<)~~~~
Azure devops專案 Deplpoyment Goups選單中Targets下也終於出現了的該機器資訊,狀態顯示Healthy表示健康可用,後續就可以將專案釋出到該機器上了