DEV Community

technonotes-hacker
technonotes-hacker

Posted on

Jenkins - 1

  • Open source integration tool.
  • It can be made as centralised server by integrating multiple source like source code management , build tools , deployment environment .
  • Complete INTEGRATION TOOL
  • Its Java based.
  • To automate the repeated task.
  • CI/CD ( continuous integration and continuous delivery )
  • Even you can do patching.
  • In simple , its a centralised server.

Advantages

  1. CI/CD
  2. Open source
  3. Community driven
  4. Browser based
  5. Supports all Operating system.
  6. Distributed build --> Master and Slave node , how ? If you are setting up Jenkins , it uses resource of the system where its installed and accordingly the Jobs will take the RAM , CPU and resources. To avoid this "Distributed build" was introduced , so that "Master and Slave node" with that the load will be distributed.
  7. We can increase the scalability of master and slave.

CI/CD Workflow

  • Commit
  • Build
  • Test
  • Stage
  • Deploy
  1. Stages will be different in other CI/CD process. Purpose will be the same.
  2. Dedicated branch for each environment it will be a best practice to avoid any confusion here.

Installation & Configuration

sudo apt-get update
java -version
Enter fullscreen mode Exit fullscreen mode

Image description

Add the official key of Jenkins and then the repo.

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

Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Image description

Now JENKINS had been installed , please check with command also whether its installed or not.

dpkg -l | grep -i jenkins

Enter fullscreen mode Exit fullscreen mode

As we have encountered error , install higher version of Java from 11 to 17 or 21.

Image description

Image description

Image description

Image description

sudo systemctl start jenkins
sudo systemctl enable jenkins
sudo systemctl status jenkins
Enter fullscreen mode Exit fullscreen mode
  • Now open the console with the IP of the system.

Image description

  • If you want to know the username , then go to below location.
cat /var/lib/jenkins/users/users.xml
/var/lib/jenkins/users/admin_17980521444909415742
Enter fullscreen mode Exit fullscreen mode

want to change the password , edit and restart the jenkins.

<hudson.security.HudsonPrivateSecurityRealm_-Details> <passwordHash>#jbcrypt:$2a$10$OTYB2osGPi/rasutjHcYOOhByiCoaEZTEQk52CABOwYdrtxeIPnBu</passwordHash>
</hudson.security.HudsonPrivateSecurityRealm_-Details>

  • Give no password for jenkins user ( as its a internal user )

Image description

  • Check whether able to get output without sudo password.

Image description

User Management & security

  • Manage Jenkins > Security

Image description

  • Trying to use the OS user for security features , lets try.
  • Add the user to the group shadow like below and restart the Jenkins.

Image description

Image description

  • Now its integrated with the OS user (sathishpy1808) , you can even login with the OS users after integrating.

Image description

Image description

Jenkins own database

  • User created in Jenkins only can login , OS users can't.

User creation

  • Change to "Jenkins own database" then only you can view the user creation option like below ,

Image description

Image description

Image description

  • Go to the ravi user profile and explore.

Image description

  • Even you can terminate all sessions from the console.
  • You can change the password also and delete option is also available.

Authorisation

  • what type of authorisation is given to the users , you can see many options in the below screen.

Image description

  • BY default --> "logged-in users can do anything" its equal to admin access --> its not advisable.
  • Try to use with user based ,

Image description

  • Also ROLE based plugin it will be useful , lets install ( mostly used plugin for role based authorisation )

Image description

Image description

Image description

  • Manage & roles won't be available at first , it will come after the plugin installation only.

Image description

  • Manage roles and assign roles are very important option.
  • Lets create a role and then assign the users.
  • Pattern based users are created only in "Item Roles". Here if any user starts with word "Manage" , it should the managing job roles.

Image description

Image description

Image description

  • Create some Jobs to test this user specification.

Image description

Image description

Image description

  • Item roles in "Assign Roles" will be useful for pattern description for users.
  • You can see all roles which are added.
  • All users are added in this console.

Image description

Image description

Image description

Image description

Job Management

  • Jobs needs to be created to perform a task.

Image description

Image description

Image description

Image description

Build Triggers

  • "Trigger builds remotely (e.g., from scripts)" --> it will trigger once some other task gets triggered.
  • "GitHub hook trigger for GITScm polling" --> once the code gets committed then only the job needs to be triggered.

Image description

Build Environment

Image description

Build Steps

  • This is the main step , you can add number of steps here.
  • Raw commands , shell script , etc.
  • Can be added like stages.

Image description

Post-build Actions

Image description

Notes

  1. https://www.jenkins.io/doc/book/installing/linux/ --> In this site , you can get the details of the key and the repo details which we have added in the first of the installation part. [TBD]
  2. What is "openjdk-17-jdk-headless package" ?
  3. Default port of Jenkins is 8080.
  4. jenkins user will be always running.

Commands Used

java -version
locate jdk
whereis java

List of errors

Job for jenkins.service failed because the control process exited with error code.

Image description

Image description

  • Now you can get the details by typing ,
journalctl -xeu jenkins.service
Enter fullscreen mode Exit fullscreen mode

Error clearly says , ( version not supported )

Dec 01 22:03:57 meet.sathishpy1808.org jenkins[40153]: Running with Java 11 from /usr/lib/jvm/java-11-openjdk-amd64, which is older than the minimum required version (J>
Dec 01 22:03:57 meet.sathishpy1808.org jenkins[40153]: Supported Java versions are: [17, 21]
Dec 01 22:03:57 meet.sathishpy1808.org jenkins[40153]: See https://jenkins.io/redirect/java-support/ for more information.
Dec 01 22:03:57 meet.sathishpy1808.org systemd[1]: jenkins.service: Main process exited, code=exited, status=1/FAILURE

Access Denied

Image description

  • change the ownership to the current user,
sudo chown -R sathishpy1808:sathishpy1808 /var/lib/jenkins/
sudo chown $(whoami) /var/lib/jenkins
Enter fullscreen mode Exit fullscreen mode

Dangling meta character '*' near index 0

Image description

Top comments (0)