---
# System prepended metadata

title: CI/CD Basic
tags: [CICD]

---

---
tags: CICD
---

# CI/CD Basic
## Jenkins Installation
[Download Jenkins](https://www.jenkins.io/download/)
[安裝參考](https://www.cnblogs.com/dotnet261010/p/11495762.html)
**更換安裝路徑** ​(方便管理,但安全性會下降)
* 移除目前的Jenkins以避免覆蓋 `sc delete jenkins`​
* Copy C:\ProgramData\Jenkins\.jenkins d:\Jenkins​
* Jenkins.xml 、Config.xml => 修改安裝路徑 (
`sc create jenkins binpath= "d:\jenkins\jenkins.exe"`​

**Install plugins** ​
* Keyboard Shortcuts => 熱鍵​
* categorized-view => Job分類​
* Stage view => 執行job的Stage分隔​
* Log Parser => 錯誤訊息判斷​
* Role-based Authorization Strategy =>登入者權限​
* Active directory => AD登入​
* ThinBackup => Jenkins 備份​
* Extended Choice Parameter => Task checkbox套件​
* Pipeline Utility Steps => groovy跑readJSON file的套件

**HotKeys**
![](https://i.imgur.com/8kLH0Gv.jpg)

**Setup Basic tools (git msbuild.exe)**
![](https://i.imgur.com/ztOnz6a.jpg)


## Create Jenkins Job

**FreeStyle**
1. Create new job
![](https://i.imgur.com/xqMK74s.jpg)
2. Setup git and workspace
![](https://i.imgur.com/GS4eLyn.jpg)
3. Build c# project
![](https://i.imgur.com/HzCkiqE.jpg)

**Pipeline**
[Groovy Formatter](https://codebeautify.org/javaviewer/cbacc095)
1. Create new job
![](https://i.imgur.com/vAHROQ1.jpg)
2. Use sample groovy
![](https://i.imgur.com/0moIZle.jpg)
3. Pipeline Syntax
3.1 Checkout Source
![](https://i.imgur.com/16TjYoy.jpg)
3.2 Nuget restore(PowerShell)
![](https://i.imgur.com/ffxDtdX.jpg)
3.3 Build: use msbuild.exe command
```
pipeline {
  agent any

  stages {
    stage('CheckoutSource') {
      steps {
        dir('D:\\JenkinsWorkspace\\DemoPipeline') {
          git credentialsId: 'sshuser', url: 'ssh://git@gitlab.net:8022/monitor.git'
        }
      }
    }
    stage('restore nuget') {
      steps {
        dir('D:\\JenkinsWorkspace\\DemoPipeline') {
          powershell 'nuget restore'
        }
      }
    }
    stage('build') {
      steps {
        powershell 'msbuild D:\\JenkinsWorkspace\\DemoPipeline\\SupportMonitor.sln'
      }
    }
  }
}
```

## Add Credential
Dashboard -> Manage Jenkins -> Credentials click Jenkins -> click Global credentials -> Add Credentials
![](https://i.imgur.com/zXSQkAm.jpg)
![](https://i.imgur.com/fpc1yaV.jpg)
Add SSH private Key
![](https://i.imgur.com/B66QGt0.jpg)

## Jenkins management console 
**Change home directory**
![](https://i.imgur.com/hf8UArj.jpg)
**Default view**
![](https://i.imgur.com/QUgqfSD.jpg)
**Executors**
![](https://i.imgur.com/6CBW9l7.jpg)
**JenkinsURL**
![](https://i.imgur.com/3JldDwU.jpg)
**Shared Library**
![](https://i.imgur.com/NbTTDgz.jpg)
**Parsing rules**
![](https://i.imgur.com/hMUJptR.jpg)


