Jenkins - Project 2 - node-todo-cicd
Clone the Project on your Local Git
git clone
https://github.com/LondheShubham153/node-todo-cicd
Create a New Repository
node-todo-cicd
on your GitHub accountCreate Personal access tokens (classic)
Let's change the URL of the remote repository in the local Git and push the code to the My Personal GitHub Repository.
From:
https://github.com/LondheShubham153/node-todo-cicd
To:https://github.com/ketangharateG/node-todo-cicd
Additional Info about the cmd:
It allows you to update the location where your local repository pushes and pulls data from.The basic syntax of the command is as follows:
git remote set-url <remote-name> <new-url>
Here's a breakdown of the components:
<remote-name>
refers to the name of the remote repository. Common default names are "origin" and "upstream," but you can use any name you've assigned to the remote.<new-url>
is the new URL you want to set for the remote repository.
Since we are using tokens for authentication, and to include an access token (such as a personal access token or OAuth token) for authentication, we specify the token in the URL itself.
Here's an example of how you can use the git remote set-url
command with a token:
git remote set-url <remote-name> <new-url-with-token>
Replace <remote-name>
with the actual remote name and <new-url-with-token>
with the desired URL including the token.
For instance, if you have a remote named "origin" and want to update its URL to include a token "my-token" in the URL, the command would look like this:
git remote set-url origin https://username:my-token@github.com/example-user/example-repo.git
In the example above, username
is your GitHub username, and my-token
is the access token associated with your account. Make sure to replace them accordingly.
By including the token in the URL, Git will use it for authentication when interacting with the remote repository.
Remember to adjust the remote name, URL, username, and token as per your specific repository and token information.
Steps Followed
git clone https://github.com/LondheShubham153/node-todo-cicd
cd node-todo-cicd
git remote -v
git remote set-url origin https://ffhhjhhjhjjhp_49pQdhOl@github.com/ketangharateG/node-todo-cicd.gi
git remote -v
git add .
git commit -m "First commit"
git branch -M main
git push -u origin main
Login to your Jenkins Dashboard > Click on New Item name it "
node-todo-cicd
" > Select "Freestyle project" > Use the "Copy from" option to create a new item from other existing itemsWe will need to make the below Configuration changes for the Item/Project:
Description
Project URL :https://github.com/ketangharateG/node-todo-cicd
Repository URL :https://github.com/ketangharateG/node-todo-cicd.git
Execute shell
docker-compose down
docker-compose up -d
Check for the Console output
Allow Traffic for 8000 Port in AWS > EC2 Security Groups > Allow inbound rules
You will be able to access the Nodejs Application now, after the successful build of the Item
Let's configure Jenkins in a way that allows you to trigger a build in Jenkins whenever changes are pushed to a GitHub repository.
To use this feature, you need to configure a Jenkins job with the appropriate settings. Here's how you can set it up:
Open Jenkins and navigate to the job configuration page for the job you want to trigger.
Scroll down to the "Build Triggers" section and check the option "GitHub hook trigger for GITScm polling."
Save the job configuration.
Go to your GitHub repository's settings page.
In the left sidebar, click on "Webhooks."
Click on the "Add webhook" button.
Enter the Jenkins URL followed by
/github-webhook/
in the "Payload URL" field.
For example, if your Jenkins server is running at:
https://your-jenkins.example.com
The payload URL would be:
https://your-jenkins.example.com/github-webhook/
.Choose the content type as "application/json."
Select "Just the push event" or any other events you want to trigger the build on.
Save the webhook configuration.
Commit the changes in a file on your GitHub Repository and check the build will trigger automatically.
- Some Important Directory to check if any error is there:
journalctl -u jenkins -fn
/var/lib/jenkins/workspace
/var/lib/jenkins/logs/
/var/log/jenkins/