###### tags: `jptw` `thesis` `technology` `jenkins` `cicd` # Notes for Jenkins ## Install Jenkins on Ubuntu > Ref: > [1] [How To Install Jenkins on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-install-jenkins-on-ubuntu-18-04) > [2] [Installing Jenkins on macOS](https://www.macminivault.com/installing-jenkins-on-macos/) ### Installation Install Java ``` $ sudo apt update $ sudo apt install openjdk-8-jdk ``` Install Jenkins ``` // add the repository key $ wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add - $ sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' // install Jenkins $ sudo apt install Jenkins $ sudo systemctl start jenkins $ sudo sysyemctl status jenkins ``` Open firewall ``` $ sudo ufw allow 8080 $ sudo ufw status ``` ### Set-up > IP address: http://localhost:8080 ![](https://i.imgur.com/aRytS2x.png) ``` $ sudo cat /var/lib/jenkins/secrets/initialAdminPassword ``` and follow [1] step-by-step. ## Setup with Github Webhook > Ref: > *[1] [原始碼管理與建置觸發程序](https://tso-liang-wu.gitbook.io/learn-ansible-and-jenkins-in-30-days/jenkins/jenkins/jenkins-scm-and-trigger) > *[2] [[CI]設定jenkins連結GitHub Private Repo by Webhook](https://medium.com/@BuzonXXXX/ci-設定jenkins連結github-private-repo-111c53d29047) > *[3] [Build A Django CI/CD Pipeline using Jenkins](https://www.codementor.io/@vahiwe/build-a-django-ci-cd-pipeline-using-jenkins-1avemkw6hq) > [4] [Git | Jenkins plugin](https://plugins.jenkins.io/git/) > [5] [透過 GitHub Webhook 讓你 push code 到 Github 就會自動觸發本地 Jenkins Pipeline](https://zoejoyuliao.medium.com/透過-github-webhook-觸發本地-jenkins-pipeline-讓你-push-code-到-github-就會自動跑-ci-cd-7c4bd7a22446) > [6] [[Day 16] 我的第一個 Jenkins Job](https://ithelp.ithome.com.tw/articles/10194160) ### Jenkins 原始碼管理 ![](https://i.imgur.com/lCRiYUn.png) Repository Url: https://github.com/{username}/{repo_name}.git https://**{token}**@github.com/{username}/{repo_name}.git ### Github :::info Settings > Developer settings > Personal access tokens > **Generate new token** ::: ![](https://i.imgur.com/qJCAjBW.png) and ==copy the **token**== :::info Project Repo > Settings > Webhook > Add webhook ::: ![](https://i.imgur.com/0Z6fxtF.png) :::warning http://127.0.0.1:8080/github-webhook/ cannot be connected IP address must be public IP or domain (or use **[ngrok](#Ngrok)**) ::: ### Ngrok > Download: https://ngrok.com/download ``` $ sudo wget "https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip" $ unzip /path/to/ngrok.zip $ cd /path/to/ngrok $ ./ngrok http 8080 ``` ![](https://miro.medium.com/max/1400/1*bxAJC-nWYzpePro24JLfMQ.gif) > Ref: > [1] [透過 GitHub Webhook 讓你 push code 到 Github 就會自動觸發本地 Jenkins Pipeline](https://zoejoyuliao.medium.com/透過-github-webhook-觸發本地-jenkins-pipeline-讓你-push-code-到-github-就會自動跑-ci-cd-7c4bd7a22446)