Giving Necessary permissions to Jenkins User
- jenkins user needs to be given necessary permissions.
- Since we use jenkins for automation if the command we execute asks for a password jenkins will halt execution
- Now lets try to give sudo permission to the jenkins user which will not ask for a password
- Note: This is a linux configuration for a jenkins user on linux node
- commands:
# become a root user sudo -i visudo # make changes as shown below and save the file
- Now lets look at the jenkins job config

Lets disect the Jenkins Free Style Project
- This is classic way of creating jenkins job.
- Jenkins freestyle project has the following sections
- General:
- This section is about describing the basic configurations of your project

- This section is about describing the basic configurations of your project
- Source Code Management:
- In this section we try to configure the version control system from where the code needs to be picked up

- In this section we try to configure the version control system from where the code needs to be picked up
- Build Triggers
- This section will help in configuring when should be job triggered/executed

- This section will help in configuring when should be job triggered/executed
- Build Environment

- Build: This is the core activity for doing ci/cd i.e. building or deploying the code

- Post Build Actions: After the build is completed (success or failure) configuring next steps is done from here

- General:
- Screenshot

- Now lets create a jenkins job by configuring SCM and build step

- NOte: To explore install tree (sudo apt install tree -y)
- Now lets explore the /var/lib/jenkins

- lets explore the /var/lib/jenkins/jobs

- we have created a job called as
exploring
- The configurations are stored as xml file under
/var/lib/jenkins/jobs/<job-name>/config.xml
- Now lets build the exploring job

- Now lets explore the workspace folder

- In the
workspace/<project-name>the files are created depending on the steps configured in jenkins job - Workspace contains the code cloned and files created as the result of the commands executed during build process.
- jobs folder will create the files when we create a job and build is generated.
- When we create any stuff in jenkins it will be stored in /var/lib/jenkins which is referred as
JENKINS_HOMEdirectory. - If you want to backup jenkins then take the backup of JENKINS_HOME directory
- Lets change the build to show environment variables. Run the jenkins job
- Following are the list of ENVIRONMENT Variables shown in output
BUILD_DISPLAY_NAME='#3' BUILD_ID='3' BUILD_NUMBER='3' BUILD_TAG='jenkins-exploring-3' BUILD_URL='http://35.86.87.190:8080/job/exploring/3/' CI='true' DBUS_SESSION_BUS_ADDRESS='unix:path=/run/user/113/bus' EXECUTOR_NUMBER='1' GIT_BRANCH='origin/master' GIT_COMMIT='71343d252fdc7b6c6f05c6ae88231445e0c72a5a' GIT_PREVIOUS_COMMIT='71343d252fdc7b6c6f05c6ae88231445e0c72a5a' GIT_PREVIOUS_SUCCESSFUL_COMMIT='71343d252fdc7b6c6f05c6ae88231445e0c72a5a' GIT_URL='https://github.com/GitPracticeRepo/understanding.git' HOME='/var/lib/jenkins' HUDSON_COOKIE='06bc3074-9d40-458a-b041-4a30789f1122' HUDSON_HOME='/var/lib/jenkins' HUDSON_SERVER_COOKIE='c175908bb1344434' HUDSON_URL='http://35.86.87.190:8080/' IFS=' ' JENKINS_HOME='/var/lib/jenkins' JENKINS_SERVER_COOKIE='c175908bb1344434' JENKINS_URL='http://35.86.87.190:8080/' JOB_BASE_NAME='exploring' JOB_DISPLAY_URL='http://35.86.87.190:8080/job/exploring/display/redirect' JOB_NAME='exploring' JOB_URL='http://35.86.87.190:8080/job/exploring/' LANG='C.UTF-8' LOGNAME='jenkins' MAIL='/var/mail/jenkins' NODE_LABELS='master' NODE_NAME='master' OPTIND='1' PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin' PPID='5405' PS1='$ ' PS2='> ' PS4='+ ' PWD='/var/lib/jenkins/workspace/exploring' RUN_ARTIFACTS_DISPLAY_URL='http://35.86.87.190:8080/job/exploring/3/display/redirect?page=artifacts' RUN_CHANGES_DISPLAY_URL='http://35.86.87.190:8080/job/exploring/3/display/redirect?page=changes' RUN_DISPLAY_URL='http://35.86.87.190:8080/job/exploring/3/display/redirect' RUN_TESTS_DISPLAY_URL='http://35.86.87.190:8080/job/exploring/3/display/redirect?page=tests' SHELL='/bin/bash' SHLVL='0' USER='jenkins' WORKSPACE='/var/lib/jenkins/workspace/exploring' WORKSPACE_TMP='/var/lib/jenkins/workspace/exploring@tmp' XDG_DATA_DIRS='/usr/local/share:/usr/share:/var/lib/snapd/desktop' XDG_RUNTIME_DIR='/run/user/113' XDG_SESSION_CLASS='background' XDG_SESSION_ID='c1' XDG_SESSION_TYPE='unspecified' _='/usr/bin/daemon' - Lets see the list of the environmental variables

- We can use this environmental variables in the build command

- Following are the list of ENVIRONMENT Variables shown in output
Lets create our first build project for java
- Before we configure building on jenkins, lets try to understand how to build a java project manually
- Lets try to build the project Refer Here hosted on github
- To build this project
- Softwares:
- git
- java 11 jdk
- maven
- Softwares:
- We have create a test server and installed the above mentioned softwares
- Executed the following commands
git clone https://github.com/graalvm/graal-js-jdk11-maven-demo
cd graal-js-jdk11-maven-demo
mvn package
-
If we want to run this as a project on our jenkins server
- we need to install maven
-
Now create a jenkins job

-
Now lets build the jenkins job
Maven
- For java applications to build the code the APACHE Ant tool was introduced where you create a configuration file
build.xmlwhere you specify the build steps once and run it multiple times using ant tool Refer Here for the sample - Maven is build with an approach
Convention over configuration - When developers build projects they use external java libraries
- Maven has an easy way to do dependency management.
- Maven can help in creating the basic folder structures
