jenkins project

jenkins project

Step 1 : In first step we have to create aws ec2 instance.

Step 2 : Run the below commands to install Java and Jenkins

sudo apt update
sudo apt install openjdk-11-jre

Step 3 : verify java is installed.

 java -version

Step 4 : Now you can processed to installing jenkins.

 curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins

Note: By default, Jenkins will not be accessible to the external world due to the inbound traffic restriction by AWS. Open port 8080 in the inbound traffic rules as show below.

  • EC2 > Instances > Click on

  • In the bottom tabs -> Click on Security

  • Security groups

  • Add inbound traffic rules as shown in the image (you can just allow TCP 8080 as well, in my case, I allowed All traffic).

  • Login to Jenkins using the below URL:

    http://:8080 [You can get the ec2-instance-public-ip-address from your AWS EC2 console page]

    Note: If you are not interested in allowing All Traffic to your EC2 instance 1. Delete the inbound traffic rule for your instance 2. Edit the inbound traffic rule to only allow custom TCP port 8080

    After you login to Jenkins, - Run the command to copy the Jenkins Admin Password - sudo cat /var/lib/jenkins/secrets/initialAdminPassword - Enter the Administrator password

  • Step 5 : Click on Install suggested plugins.

  • Step 6 : create jenkins account .

  • Install the Docker Pipeline plugin in Jenkins:

    • Log in to Jenkins.

    • Go to Manage Jenkins > Manage Plugins.

    • In the Available tab, search for "Docker Pipeline".

    • Select the plugin and click the Install button.

    • Restart Jenkins after the plugin is installed.

and click on restart the jenkins

  • Step 7 : Docker Slave Configuration

    Run the below command to Install Docker.

  •        sudo apt update
          sudo apt install docker.io
    

    Grant Jenkins user and Ubuntu user permission to docker deamon.

      sudo su - 
      usermod -aG docker jenkins
      usermod -aG docker ubuntu
      systemctl restart docker
    

    Step 8 : after that switch user to jenkins.

  •        su - jenkins
    

    Step 8 : In this step we have to logout from jenkins.

  •        logout
    
  • Step 9 : And again swith user to jenkins using below command.

  •        usermod -aG docker jenkins
           su - jenkins
    

    Step 10 : verify youre docker is install or not by running below command.

  •        docker run hello-world
    
  • Once you are done with the above steps, it is better to restart Jenkins.

      http://<ec2-instance-public-ip>:8080/restart
    

    The docker agent configuration is now successful.

  • Step 11 : click on a new item

  • Step 12 :

    Step 12 : project 1 : A simple jenkins pipeline to verify if the docker slave configuration is working as expected.

  • Note: You can take code from my github account: https://github.com/Shreyashbhise/jenkins-project

  • Step 13 : In Definition you have to select pipeline script from scm and in scm you have to select git. And in repository url copy the link of my url or your url.

  • Step 14 : In Branch specifier (blank of 'any') select the main or master branch.

  • ,and in script path select the folder name , save it.

  • Step 15 : Click on Build Now option.

  • your pipeline is finally build for A simple jenkins pipeline to verify if the docker slave configuration is working as expected.

step 15 : project 2: Multi Stage Multi Agent

Set up a multi stage jenkins pipeline where each stage is run on a unique agent. This is a very useful approach when you have multi language application or application that has conflicting dependencies.

Step 16 : for this second project you just need to change the script path.