Let’s build a complete CI/CD pipeline for your Node.js application! 🚀
How’s Day 23 coming along?
Day 23 focused on mastering the basics of Jenkins CI/CD. Today, you’ll elevate your skills by creating a full CI/CD pipeline project from start to finish.
Since you’ve already worked with Docker and Docker Compose, this project will integrate those tools into a real-world workflow. Ready to dive in and make it happen?
Step 1: Fork the Repository
Go to the GitHub repository: node-todo-app
Click the Fork button located in the top-right corner of the page.
Congratulations! You now have your own copy of the repository!
Step 2: Set Up SSH Keys
Open your terminal or command prompt.
Generate an SSH key pair by running the command
ssh-keygen
When prompted:
Specify the file location to save the key (or press Enter to accept the default location, typically
~/.ssh/id_rsa
).Enter a passphrase (optional but recommended) for added security.
The result will be two files:
Private Key:
id_rsa
(keep this secure!)Public Key:
id_
rsa.pub
.
Step 3: Add the SSH Key to GitHub
Copy the contents of the public key:
cat ~/.ssh/id_rsa.pub
Go to GitHub > Settings > SSH and GPG Keys > New SSH Key.
Paste the copied public key into the "Key" field.
Click Add SSH Key.
E.g.:-
Step 4: Install the GitHub Plugin in Jenkins
Go to Jenkins > Manage Jenkins > Manage Plugins.
Under the Available tab, search for GitHub Plugin.
Select it and click Install Without Restart.
Wait for the installation to complete.
Step 5: Create a New Jenkins Job
In Jenkins, click on New Item.
Enter an item name for your job (e.g., Node-ToDo-App).
Select Freestyle Project and click OK.
Step 6: Configure Source Code Management
Inside your Jenkins job configuration:
Go to the Source Code Management section.
Select Git.
Enter the Repository URL:
- Use the SSH URL of your forked repository (e.g.,
git@github.com
:<your-username>/node-todo-app.git
).
- Use the SSH URL of your forked repository (e.g.,
Add Credentials:
Click Add > Jenkins.
Choose SSH Username with Private Key.
Enter your GitHub username and paste the contents of your private key (
id_rsa
).Save.
E.g.:-
Step 7: Test Jenkins and GitHub Connection
Save the configuration and click Build Now in your Jenkins job.
Verify that Jenkins successfully clones the repository without errors.
Step 8: Manually executed the Node.js project by following these steps:
- Installed Node.js: Ran the command to install Node.js, which is required to run the application:
sudo apt install nodejs
- Installed npm (Node Package Manager):
Installed npm to manage dependencies for the project:sudo apt install npm
- Installed Project Dependencies: Used npm to install all dependencies listed in the
package.json
file:
sudo npm install
- Started the Application:
Ran the application using the Node.js runtime:
node app.js
Output:- The application is running on the server's public IP address, accessible via port 8000.