DevOps Classroom notes 26/Nov/2023

Jenkins contd

Configuring email notifications in jenkins

  • Manage Jenkins => System => Email Notification
  • use mailtrap details with tls enabled on port 587 and test configuration

Environment variables in jenkins

  • Jenkins master injects environmetal variables with information about various aspects such as
    • GIT DETAILS
    • BUILD DETAILS
    • WORKSPACE DETAILS
  • Navigate below for the whole list
JENKINS_HOME=/var/lib/jenkins
GIT_PREVIOUS_SUCCESSFUL_COMMIT=c4081c09f8231a44e7d8d898a1ad4476f827da36
USER=jenkins
CI=true
RUN_CHANGES_DISPLAY_URL=http://34.222.10.63:8080/job/spring-petclnic-daybuild/5/display/redirect?page=changes
NODE_LABELS=built-in
HUDSON_URL=http://34.222.10.63:8080/
GIT_COMMIT=c4081c09f8231a44e7d8d898a1ad4476f827da36
HOME=/var/lib/jenkins
BUILD_URL=http://34.222.10.63:8080/job/spring-petclnic-daybuild/5/
HUDSON_COOKIE=29a01ce1-e58d-4b7a-9b23-ae1975c228d1
JENKINS_SERVER_COOKIE=c55384f90aa648b4
NOTIFY_SOCKET=/run/systemd/notify
SYSTEMD_EXEC_PID=375
WORKSPACE=/var/lib/jenkins/workspace/spring-petclnic-daybuild
LOGNAME=jenkins
NODE_NAME=built-in
JOURNAL_STREAM=8:17665
RUN_ARTIFACTS_DISPLAY_URL=http://34.222.10.63:8080/job/spring-petclnic-daybuild/5/display/redirect?page=artifacts
EXECUTOR_NUMBER=1
GIT_BRANCH=origin/main
RUN_TESTS_DISPLAY_URL=http://34.222.10.63:8080/job/spring-petclnic-daybuild/5/display/redirect?page=tests
BUILD_DISPLAY_NAME=#5
HUDSON_HOME=/var/lib/jenkins
JOB_BASE_NAME=spring-petclnic-daybuild
PATH=/usr/lib/jvm/java-1.17.0-openjdk-amd64/bin:/usr/lib/jvm/java-1.17.0-openjdk-amd64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
INVOCATION_ID=a1556e10e7bb446795e87a1e2a56deca
BUILD_ID=5
BUILD_TAG=jenkins-spring-petclnic-daybuild-5
LANG=C.UTF-8
JENKINS_URL=http://34.222.10.63:8080/
JOB_URL=http://34.222.10.63:8080/job/spring-petclnic-daybuild/
GIT_URL=https://github.com/dummyrepos/spring-petclinic-nov23.git
BUILD_NUMBER=5
SHELL=/bin/bash
RUN_DISPLAY_URL=http://34.222.10.63:8080/job/spring-petclnic-daybuild/5/display/redirect
HUDSON_SERVER_COOKIE=c55384f90aa648b4
JOB_DISPLAY_URL=http://34.222.10.63:8080/job/spring-petclnic-daybuild/display/redirect
JOB_NAME=spring-petclnic-daybuild
JAVA_HOME=/usr/lib/jvm/java-1.17.0-openjdk-amd64
PWD=/var/lib/jenkins/workspace/spring-petclnic-daybuild
GIT_PREVIOUS_COMMIT=c4081c09f8231a44e7d8d898a1ad4476f827da36
WORKSPACE_TMP=/var/lib/jenkins/workspace/spring-petclnic-daybuild@tmp
  • Using environmental variables we have copied the jar into /tmp folder
#!/bin/bash
# create a folder in /tmp
TARGET="/tmp/$JOB_BASE_NAME/$BUILD_ID"
SOURCE="$WORKSPACE/target/spring-petclinic*.jar"
mkdir -p $TARGET
cp $SOURCE $TARGET
  • For custom needs ENVIRONMENTAL Variables are useful
  • Lets assume i need to copy the jar file in the folder which user will pass.
  • To enable users passing information we have parameters in Jenkins
  • Lets create a parameter where user can enter folder





Executors in Jenkins

  • In jenkins every node will have executors.
  • The number of parallel projects which you can build depend on number of executors
  • Always ensure you terminate the jobs by defining the hard limits of time to keep your executors ready to serve other projects

Distributed Builds in jenkins

  • Jenkins allows to add nodes to Master
  • Each node will have labels
  • Every Jenkins job that needs to run on a specific node should match the label.
  • There are two ways of connecting nodes
    • Linux: By configuring ssh connections
    • Windows: Configure using
      • JNLP
      • Windows Service

Scenario: Lets create two nodes

  • Lets create two nodes
  • first node:
    • LABEL: MAVEN, JDK_17
    • Softwares:
      • Openjdk 17
      • maven
    • Executor: 4
  • Screenshots for first node:










  • second node:
  • Third node:
    • LABEL: TERRAFORM, K8S
    • Softwares:
  • On Linux nodes, Jenkins expects JDK to be present

Jenkins Plugins

  • Plugins provide additional functionality to jenkins
  • In free style projects the functionality will be provided as UI (User interface) and for pipeline projects it provides steps.
  • Jenkins plugins can be developed in java language.
  • Jenkins custom plugins will have two valid extensions
    • hpi (hudson plugin interface)
    • jpi (jenkins plugin interface)
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%