---
# System prepended metadata

title: Set CICD with Jenkins
tags: [common]

---

---
title: Set CICD with Jenkins
tags: common
--- 

:::danger
If you are running Jenkins locally, use ngrok to get outer access in order to set your webhook
:::

* Login to ngrok, copy and paste this inside your ngrok folder
![](https://i.imgur.com/i7mR8Y8.png)

![](https://i.imgur.com/UElp8ZZ.png)


* then run ngrok in the backgroud by adding & sign in the end of your command


`nohup ./ngrok http 8080 &`

![](https://i.imgur.com/D2ORWXj.png)

* Then you can check your tunnels here!


* Copy the tunnel and add ==/github/webhook/== in the end of the url, set it as webhook in your GitHub repo settings
![](https://i.imgur.com/n840MDp.png)


* Create a ==New Item== on Jenkins, select ==Pipeline==, and click on ==OK==
![](https://i.imgur.com/i2JbCAZ.png)

![](https://i.imgur.com/1cEjo6p.png)

![](https://i.imgur.com/VuTI2Ss.png)


### Jenkinsfile
```javascript=1
pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                echo '---start build---'
                nodejs(nodeJSInstallationName: 'node14.15.4') {
                sh 'npm i'
                sh 'npm run build'
                }
            }
        }
        stage('Test') {
            steps {
                echo '---start test---'
                echo 'Do check'
            }
        }
        stage('Deploy') {
            steps {
                echo '---start deploy---'
                sh 'ssh -T pmduser@10.20.30.215 "cd ~/Desktop/cicd/jenkins_home/workspace && docker-compose up -d --build"'
            }
        }
    }
}
```

### docker-compose.yml
```dockerfile=1
version: '3.7'
services:
  gqlts:
    container_name: gqlts
    build: ./gqlts/
    environment:
      - TZ=Asia/Taipei
    ports:
      - '8081:8081'
    restart: always

  frontend-admin:
    container_name: frontend-admin
    build: ./frontend-admin/
    environment:
      - TZ=Asia/Taipei
    ports:
      - '8000:8000'
    restart: always
```