Jenkins - Project 2 - node-todo-cicd

  1. Clone the Project on your Local Git
    git clone https://github.com/LondheShubham153/node-todo-cicd

  2. Create a New Repository node-todo-cicd on your GitHub account

  3. Create Personal access tokens (classic)

  4. 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

  1. 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 items

    We 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

  2. Check for the Console output

  3. Allow Traffic for 8000 Port in AWS > EC2 Security Groups > Allow inbound rules

  4. You will be able to access the Nodejs Application now, after the successful build of the Item

  5. 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:

    1. Open Jenkins and navigate to the job configuration page for the job you want to trigger.

    2. Scroll down to the "Build Triggers" section and check the option "GitHub hook trigger for GITScm polling."

    3. Save the job configuration.

    4. Go to your GitHub repository's settings page.

    5. In the left sidebar, click on "Webhooks."

    6. Click on the "Add webhook" button.

    7. 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/.

    8. Choose the content type as "application/json."

    9. Select "Just the push event" or any other events you want to trigger the build on.

    10. Save the webhook configuration.

    11. 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/