-
Create EC2 Instance with 200 G disk space from amazon console
1.1 Make sure security group has 8080 accessible to all -
SSH in to the instance and run following commands to install Java 8
2.1 $sudo apt update -y
2.2 $sudo apt install openjdk-8-jdk -y -
Visit https://pkg.jenkins.io/debian-stable/ and copy the installation commands which are as below
3.1 $wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add - -
Then add the following entry in your /etc/apt/sources.list
4.1 $deb https://pkg.jenkins.io/debian-stable binary/ -
Run the following command to install jenkins package
5.1 $sudo apt-get update -y
5.2 $sudo apt-get install jenkins -y -
Start Jenkins Server as a Service and Enable at boot time
6.1 $sudo systemctl start jenkins
6.2 $sudo systemctl enable jenkins
6.3 $sudo systemctl status jenkins -
Copy the initial admin password which will be asked when you launch web ui first time
7.1 $sudo cat /var/lib/jenkins/secrets/initialAdminPassword -
Open Jenkins web ui
http://<publick ip>:8080/and enter the password copied in previous step -
Install Suggested Plugins
-
Access Jenkins UI at http://:8080/
----- This completes the Jenkins Installtion part ------
-
Ssh in to the instance give jenkins user sudo access without any password prompt
2.1 $sudo vi /etc/sudoers
Add the following line of code to the file. I added this after the root user in the User privilege specification section:
2.2 $jenkins ALL=(ALL) NOPASSWD:ALL -
Switch to jenkins user
2.1 sudo su jenkins
2.2 cd //To take you to jenkins home directory which is /var/lib/jenkins for default jenkins installation -
Generate ssh keys and add them to github repo as deploy keys
3.1 $ssh-keygen
#keep pressing enter to choose the default options
3.2 $cat ~/.ssh/id_rsa.pub // or /var/lib/jenkins/.ssh/id_rsa.pub
3.3 Go to https://github.com/go360-io/orion-ros2-reference/settings
3.4 Click onDeploy Keysin the left panel
3.5 Click onAdd deploy keyand paste your public key here
3.6 Click onWebhooksand addhttp://<publick ip>:8080/github-webhook/ -
Install necessary jenkins plugin
4.1 Login in to jenkins web ui
4.2 Go toJenkins->Manage Jenkins->Manage Pluginsinstall these additional plugins
->GitHub Integration Plugin
->Pipeline: Multibranch with defaults
->Slack Notification Plugin -
Configure jenkins for Github integreation
5.1 Go toJenkins->Manage Jenkins->Configure System
5.2 Scroll down and you will find the GitHub Pull Requests checkbox. In the Published Jenkins URL, add the repository link
->https://github.com/go360-io/orion-ros2-referencesave changes -
Configure Build pipeline
6.1 Go toJenkins->New
6.2 Enter some name for the pipe line and choose type asMultibranch pipeline with defaults
6.3 Once created go toConfigure
6.4 Scroll down toBuild ConfigurationchooseBy default jenkinsfileand enter script id asorian-jenkins-config(or whatever you choose you need to save the config file with same name/id)
6.5 check: Run default Jenkinsfile within Groovy sandbox and save
6.6 Go toManage Jenkins->Managed files
6.7 ClickAdd a new configChoose Type asGroovy fileand give id asorian-jenkins-config(Or whatever id you configured in the job in step 6.4)
6.8 Copy the contents from the file ./jenkins/orian-jenkins-config.groovy here and save -
Configure slack notification (Optional)
7.1 Create a public channel sayorion-ci-cd-notification
7.2 Go tochannel settingsandAdd an app
7.3 ChooseJenkins CI
7.4 Once select it will generate atokenfor you
7.5 Go toJenkins->Manage Jenkins->Configure System
7.6 Scroll down toSlack-> Enter yourworkspacename -> Credentials-> typesecret textand use thetokengenerated by slack -> Default Channel:orion-ci-cd-notifications(or whatever you named your public channel) -> ClickTest Connectionto send a test notification -> UncommentnotifyBuild()function call in the orian-jenkins-config file