It is the combined software practice of continuous integration (CI), continuous delivery (CD) and continuous deployment (CDE). This methodology helps to frequently deliver applications to end-users via the introduction of automation in the stages of the software development lifecycle (SDLC).
- Continuous integration is the practice of automating the integration of code changes from multiple developers into a single software project
- Goal is to deal with bugs quicker, reduce the time for software updates and improve software quality
- Continuous delivery is the practice of automatically preparing code changes for release
- Following on from CI, all code changes are deployed to a testing environment
- After this stage, the software product will be deployment-ready
- Continuous deployment automates the process of deploying code changes directly onto a live environment, so that the software product is visible to the end-usr
- An open source software tool used to build CICD pipelines
- Automated messages sent from apps when something happens
- In Jenkins, webhooks are a mechanism to automatically trigger the build of a Jenkins project in response to a commit pushed to a Git repository
- Add a webhook by accessing webhooks with repository settings page and then add webhook
- Create a new SSH key pair in the
.ssh
folder with command (found in this repository-ssh-keygen -t rsa -b 4096 -C "(insert your GitHub email)"
- Name the keys appropriately
- Navigate to your selected repository
- Go to Settings -> Deploy keys -> Add deploy key and then paste the public key into this section
- Go to Settings -> Webhooks -> Add webhook and paste the Jenkins URL into Payload URL with the extension "/github-webhook/"
The purpose of this job is to build a continuous integration process to integrate the testing of the commits between localhost - GitHub - Jenkins
- From the main Jenkins Dashboard select New item -> Enter an item name -> Freestyle Project
- This is now the Configuration page
- In General select
- Discard Old Builds and max 3 builds- this keeps server space free and will delete the oldest build if the number of builds exceeds 3
- GitHub project and put the HTTPS key of your selected GitHub repository
- In Office 365 Connector select
- Restrict where this project can be run and Label Expression is sparta-ubuntu-node
- This ensures the project is run in a specified Agent node
- In Source Code Management select
- Git
- In Repositories, paste the SSH link of the selected repository
- In Credentials, add the private key
- In Branches to build, select main
- In Build Triggers select
- GitHub hook trigger for GitScm polling- Jenkins will receive a webhook trigger from GitHub and then run the project
- In Build Environment select
- Provide Node and npm bin/ folder to PATH- this allows the shell to recognise npm commands
- In Build select
- Add build step -> Execute shell:
cd app
npm install && npm install mongoose && npm install express
npm test
Repeat the steps in Job 1 and change the following sections:
- Source Code Management
- Branches to build to dev
- Additional Behaviours -> Name of repository- origin -> Branch to merge to- main
- Post-build Actions
- Git Publisher -> Push Only if Build Succeeds -> Merge Results
This job will only be triggered if the previous jobs are successful
- Create EC2 instance with:
- Security Group that allows port 22, 3000 and 80
- Port 22 source is the Jenkins server IP
- Select the relevant key pair
- In Jenkins repeat the steps for Job 1 with following amendments:
- Source Code Management- None
- Build Environment- Provide Node and npm bin/ folder to PATH and SSH Agent (add pem file)
- Build- Execute Shell with following script
rm -rf eng84_cicd_jenkins*
git clone -b main https://github.com/Olejekglejek/CI_CD_Jenkins.git
rsync -avz -e "ssh -o StrictHostKeyChecking=no" app ubuntu@deploy_public_ip:/home/ubuntu/app
rsync -avz -e "ssh -o StrictHostKeyChecking=no" environment ubuntu@deploy_public_ip:/home/ubuntu/app
ssh -A -o "StrictHostKeyChecking=no" ubuntu@deploy_public_ip <<EOF
# 'kill' all running instances of node.js
killall npm
# run provisions file for dependencies
cd /home/ubuntu/app/environment/app
chmod +x provision.sh
./provision.sh
# Install npm for remaining dependencies
cd /home/ubuntu/app/app
sudo npm install
node seeds/seed.js
# Run the app
node app.js &
EOF
'''