# Jenkins透過SSH連線到測試機 :::info 目的: 用Jenkins SSH連線測試機,達到自動整合並部署到目標資料夾。 ::: 1. 到Jenkins 新增作業選擇「建置Free-Style軟體專案」 2. 建置區塊新增建置步驟「Execute shell Script on remote host using ssh」 3. SSH Site 選擇之前設定好的IP位址 4. 在Command的地方輸入連到遠端伺服器要下的Windows指令: * 用[rd](https://docs.microsoft.com/zh-tw/windows-server/administration/windows-commands/rd)指令刪除舊的暫存資料夾 ``` rd /s /q [暫存資料夾路徑] ``` * 再做一次暫存資料夾 ``` mkdir [暫存資料夾路徑] ``` **Clone** * 從GitLab把欲clone的分支clone到暫存資料夾 ``` git -c http.sslVerify=false clone -b [分支名稱] https://[git路徑].git [暫存資料夾路徑] ``` **Restore** * 用[Nuget.exe](https://docs.microsoft.com/zh-tw/nuget/consume-packages/package-restore#restore-using-the-nugetexe-cli)還原Nuget套件(若git有包含packages則可省略這步驟) ``` [Nuget.exe路徑] restore [Solution檔路徑] ``` **Build & Deploy** * 用[MSBuild](https://docs.microsoft.com/zh-tw/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/command-line-deployment)建置並發佈專案 ``` [MSBuild路徑] [Solution檔路徑] /p:DeployOnBuild=true /p:PublishProfile=[發佈檔檔名] ``` p.s. 若要[部署個別專案](https://docs.microsoft.com/zh-tw/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/command-line-deployment#deploying-the-solution-versus-deploying-individual-projects)時則將[Solution檔路徑(.sln)]改成[專案檔路徑(.csproj)] * 刪除要忽略的Web.config設定檔 ``` del [發佈路徑]\*Web.config* ``` * 用[xcopy](https://docs.microsoft.com/zh-tw/windows-server/administration/windows-commands/xcopy)指令複製剩餘要的檔案到目的地 >/e :複製所有子目錄,即使它們是空的。 /y :隱藏提示確認您想要覆寫現有的目的檔案。 ``` xcopy [發佈路徑] [目的路徑] /e /y ``` 5. 最後,Command下面的Execute each line一定要打勾  ###### tags: `Jenkins`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up