iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 22
0
Microsoft Azure

Azure 的自我修煉系列 第 22

Day22 整合CI測試到 Azure Pipeline 服務

  • 分享至 

  • twitterImage
  •  

整合CI測試到 Azure Pipeline 服務

CI(Continuous integration),即是「持續整合」,
上一篇我們實作了 Razor ASP.NET Core 中的頁面單元測試,
今天來整合到 Azure PipeLine 服務

創建 YAML檔案

創建 Yaml 檔案

touch azure-pipelines.yml

內容如下

# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

variables:
  buildConfiguration: 'Release'

steps:
- task: DotNetCoreCLI@2
  inputs:
    version: '3.1.401'
    command: 'build'
    arguments: '--configuration $(buildConfiguration)'
  displayName: 'dotnet build $(buildConfiguration)'

- task: DotNetCoreCLI@2
  inputs:
    version: '3.1.401'
    command: test
    projects: '**/*Tests/*.csproj'
    arguments: '--configuration $(buildConfiguration) --collect "Code coverage"'
  displayName: 'dotnet test $(buildConfiguration)'


- task: DotNetCoreCLI@2
  inputs:
    version: '3.1.401'
    command: publish
    publishWebProjects: True
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
    zipAfterPublish: True
  displayName: 'dotnet publish $(buildConfiguration)'

加入Git版本

git status
git add .
git commit -m "add azure-pipelines.yml"

https://ithelp.ithome.com.tw/upload/images/20200922/20072651kNIW9iP9OK.png

專案上傳遠端

在Github 創建專案
https://ithelp.ithome.com.tw/upload/images/20200922/20072651E0q9BWG6hx.png

本機的git加入遠端連結與上傳

# 加入 Github 倉庫連結
git remote add origin https://github.com/pellok/PellokITHomePipeline.git
# 上傳程式碼
git push -u origin master

https://ithelp.ithome.com.tw/upload/images/20200922/20072651gATCITr1c7.png

創建PipeLine

名稱: PellokITHomePipeLine
GitHub倉庫: https://github.com/pellok/PellokITHomePipeline.git
主要分支: master
倉庫類型: github

az pipelines create --name "PellokITHomePipeLine" --description 'Pipeline for PellokITHomePipeLine' --repository https://github.com/pellok/PellokITHomePipeline.git --branch master --repository-type github

https://ithelp.ithome.com.tw/upload/images/20200922/20072651TPRiunOL16.png

在實作的過程中,遇到一個問題: azure-pipelines.yml 語法問題
https://ithelp.ithome.com.tw/upload/images/20200922/20072651hTePSneehZ.png
解決步驟:先比較 azure-pipelines.yml 和之前的版本有什麼不一樣,
發現原來是多了空格和排版問題,yaml很重視排版,如果排版縮排有錯,
就會出現上面語法問題。

相關連結:

上一篇 Day 21 實作 Razor ASP.NET Core 中的頁面單元測試
下一篇 Day23 介紹 Azure Resource Manager (ARM) 範本


上一篇
Day 21 實作 Razor ASP.NET Core 中的頁面單元測試
下一篇
Day23 介紹 Azure Resource Manager (ARM) 範本
系列文
Azure 的自我修煉30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言