Saturday 6 June 2020

Jenkins Startup and Configuration

Steps to setup jenkins on ubuntu:-

-After installation. check the jenkins services running on not on the server.

sudo service jenkins status
-Check Port 8080 on server. It should be accessible for HTTP.
-Open browser & Enter <IP-Address>:<Port> to access the jenkins web page:-

http://3.21.248.164:8080/login?from=%2F
-Get password to login inside jenkins for configuration.

ubuntu@ip-172-31-3-216:~$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword
7bbef0e31c5044dcbbbe1b2cdafc8638











- Copy this password in web page and click on continue. 
- Click on Install suggested plugins.







-Check jenkins users and setting in the machine.

ubuntu@ip-172-31-3-216:~$ sudo /etc/users
sudo: /etc/users: command not found
ubuntu@ip-172-31-3-216:~$ sudo /etc/passwd
sudo: /etc/passwd: command not found
ubuntu@ip-172-31-3-216:~$ sudo cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-network:x:100:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin
systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
systemd-timesync:x:102:104:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin
messagebus:x:103:106::/nonexistent:/usr/sbin/nologin
syslog:x:104:110::/home/syslog:/usr/sbin/nologin
_apt:x:105:65534::/nonexistent:/usr/sbin/nologin
tss:x:106:111:TPM software stack,,,:/var/lib/tpm:/bin/false
uuidd:x:107:112::/run/uuidd:/usr/sbin/nologin
tcpdump:x:108:113::/nonexistent:/usr/sbin/nologin
sshd:x:109:65534::/run/sshd:/usr/sbin/nologin
landscape:x:110:115::/var/lib/landscape:/usr/sbin/nologin
pollinate:x:111:1::/var/cache/pollinate:/bin/false
ec2-instance-connect:x:112:65534::/nonexistent:/usr/sbin/nologin
systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin
ubuntu:x:1000:1000:Ubuntu:/home/ubuntu:/bin/bash
lxd:x:998:100::/var/snap/lxd/common/lxd:/bin/false
jenkins:x:113:119:Jenkins,,,:/var/lib/jenkins:/bin/bash
ubuntu@ip-172-31-3-216:~$

Install Jenkins on Ubuntu

Jenkins Prerequisites :-





Minimum hardware requirements:
256 MB of RAM
1 GB of drive space (although 10 GB is a recommended minimum if running Jenkins as a Docker container)

Recommended hardware configuration for a small team:
1 GB+ of RAM
50 GB+ of drive space

ubuntu@ip-172-31-3-216:~$ java -version

Command 'java' not found, but can be installed with:

sudo apt install default-jre              # version 2:1.11-72, or
sudo apt install openjdk-11-jre-headless  # version 11.0.7+10-3ubuntu1
sudo apt install openjdk-13-jre-headless  # version 13.0.3+3-1ubuntu2
sudo apt install openjdk-14-jre-headless  # version 14.0.1+7-1ubuntu1
sudo apt install openjdk-8-jre-headless   # version 8u252-b09-1ubuntu1

ubuntu@ip-172-31-3-216:~$ sudo apt install openjdk-11-jre-headless
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  ca-certificates-java fontconfig-config fonts-dejavu-core java-common libavahi-client3 libavahi-common-data libavahi-common3 libcups2
  libfontconfig1 libjpeg-turbo8 libjpeg8 liblcms2-2 libnspr4 libnss3 libpcsclite1 libxi6 libxrender1 libxtst6 x11-common
Suggested packages:
  default-jre cups-common liblcms2-utils pcscd libnss-mdns fonts-dejavu-extra fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei
  | fonts-wqy-zenhei fonts-indic
The following NEW packages will be installed:
  ca-certificates-java fontconfig-config fonts-dejavu-core java-common libavahi-client3 libavahi-common-data libavahi-common3 libcups2
  libfontconfig1 libjpeg-turbo8 libjpeg8 liblcms2-2 libnspr4 libnss3 libpcsclite1 libxi6 libxrender1 libxtst6 openjdk-11-jre-headless
  x11-common
0 upgraded, 20 newly installed, 0 to remove and 51 not upgraded.
Need to get 40.6 MB of archives.
After this operation, 181 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 java-common all 0.72 [6816 B]
Get:2 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 libavahi-common-data amd64 0.7-4ubuntu7 [21.4 kB]
Get:3 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 libavahi-common3 amd64 0.7-4ubuntu7 [21.7 kB]
Get:4 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 libavahi-client3 amd64 0.7-4ubuntu7 [25.5 kB]
Get:5 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 libcups2 amd64 2.3.1-9ubuntu1.1 [233 kB]
Get:6 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 liblcms2-2 amd64 2.9-4 [140 kB]
Get:7 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 libjpeg-turbo8 amd64 2.0.3-0ubuntu1 [118 kB]
Get:8 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 libjpeg8 amd64 8c-2ubuntu8 [2194 B]
Get:9 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 fonts-dejavu-core all 2.37-1 [1041 kB]
Get:10 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 fontconfig-config all 2.13.1-2ubuntu3 [28.8 kB]
Get:11 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 libfontconfig1 amd64 2.13.1-2ubuntu3 [114 kB]
Get:12 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 libnspr4 amd64 2:4.25-1 [107 kB]
Get:13 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 libnss3 amd64 2:3.49.1-1ubuntu1 [1171 kB]
Get:14 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 libpcsclite1 amd64 1.8.26-3 [22.0 kB]
Get:15 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 libxi6 amd64 2:1.7.10-0ubuntu1 [29.9 kB]
Get:16 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 libxrender1 amd64 1:0.9.10-1 [18.7 kB]
Get:17 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 x11-common all 1:7.7+19ubuntu14 [22.3 kB]
Get:18 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 libxtst6 amd64 2:1.2.3-1 [12.8 kB]
Get:19 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 openjdk-11-jre-headless amd64 11.0.7+10-3ubuntu1 [37.4 MB]
Get:20 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 ca-certificates-java all 20190405ubuntu1 [12.2 kB]
Fetched 40.6 MB in 1s (42.8 MB/s)
Selecting previously unselected package java-common.
(Reading database ... 59604 files and directories currently installed.)
Preparing to unpack .../00-java-common_0.72_all.deb ...
Unpacking java-common (0.72) ...
Selecting previously unselected package libavahi-common-data:amd64.
....
....
....
Adding debian:Cybertrust_Global_Root.pem
Adding debian:T-TeleSec_GlobalRoot_Class_3.pem
Adding debian:ePKI_Root_Certification_Authority.pem
Adding debian:GeoTrust_Universal_CA.pem
done.
Processing triggers for libc-bin (2.31-0ubuntu9) ...
Processing triggers for systemd (245.4-4ubuntu3) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for ca-certificates (20190110ubuntu1) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...

done.
done.
Setting up openjdk-11-jre-headless:amd64 (11.0.7+10-3ubuntu1) ...
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/rmid to provide /usr/bin/rmid (rmid) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/java to provide /usr/bin/java (java) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/keytool to provide /usr/bin/keytool (keytool) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jjs to provide /usr/bin/jjs (jjs) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/pack200 to provide /usr/bin/pack200 (pack200) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/rmiregistry to provide /usr/bin/rmiregistry (rmiregistry) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/unpack200 to provide /usr/bin/unpack200 (unpack200) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/bin/jfr to provide /usr/bin/jfr (jfr) in auto mode
update-alternatives: using /usr/lib/jvm/java-11-openjdk-amd64/lib/jexec to provide /usr/bin/jexec (jexec) in auto mode
ubuntu@ip-172-31-3-216:~$

Install Jenkins (Long Term Support release):-

ubuntu@ip-172-31-3-216:~$ wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
OK

ubuntu@ip-172-31-3-216:~$ sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > \
>     /etc/apt/sources.list.d/jenkins.list'

ubuntu@ip-172-31-3-216:~$ sudo apt-get update
Hit:1 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:3 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu focal-security InRelease
Ign:5 https://pkg.jenkins.io/debian-stable binary/ InRelease
Hit:6 https://pkg.jenkins.io/debian-stable binary/ Release
Reading package lists... Done

ubuntu@ip-172-31-3-216:~$ sudo apt-get install jenkins
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  daemon net-tools
The following NEW packages will be installed:
  daemon jenkins net-tools
0 upgraded, 3 newly installed, 0 to remove and 51 not upgraded.
Need to get 65.1 MB of archives.
After this operation, 67.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/universe amd64 daemon amd64 0.6.4-1build2 [96.3 kB]
Get:2 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 net-tools amd64 1.60+git20180626.aebd88e-1ubuntu1 [196 kB]
Get:3 https://pkg.jenkins.io/debian-stable binary/ jenkins 2.222.4 [64.8 MB]
Fetched 65.1 MB in 8s (8376 kB/s)
Selecting previously unselected package daemon.
(Reading database ... 60193 files and directories currently installed.)
Preparing to unpack .../daemon_0.6.4-1build2_amd64.deb ...
Unpacking daemon (0.6.4-1build2) ...
Selecting previously unselected package net-tools.
Preparing to unpack .../net-tools_1.60+git20180626.aebd88e-1ubuntu1_amd64.deb ...
Unpacking net-tools (1.60+git20180626.aebd88e-1ubuntu1) ...
Selecting previously unselected package jenkins.
Preparing to unpack .../jenkins_2.222.4_all.deb ...
Unpacking jenkins (2.222.4) ...
Setting up net-tools (1.60+git20180626.aebd88e-1ubuntu1) ...
Setting up daemon (0.6.4-1build2) ...
Setting up jenkins (2.222.4) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for systemd (245.4-4ubuntu3) ...
ubuntu@ip-172-31-3-216:~$

Check Jenkins Status:-

ubuntu@ip-172-31-3-216:~$ sudo service jenkins status
● jenkins.service - LSB: Start Jenkins at boot time
     Loaded: loaded (/etc/init.d/jenkins; generated)
     Active: active (exited) since Sat 2020-06-06 19:54:41 UTC; 12min ago
       Docs: man:systemd-sysv-generator(8)
      Tasks: 0 (limit: 1145)
     Memory: 0B
     CGroup: /system.slice/jenkins.service
ubuntu@ip-172-31-3-216:~$ sudo service jenkins status
● jenkins.service - LSB: Start Jenkins at boot time
     Loaded: loaded (/etc/init.d/jenkins; generated)
     Active: active (exited) since Sat 2020-06-06 19:54:41 UTC; 12min ago
       Docs: man:systemd-sysv-generator(8)
      Tasks: 0 (limit: 1145)
     Memory: 0B
     CGroup: /system.slice/jenkins.service
Jun 06 19:54:40 ip-172-31-3-216 systemd[1]: Starting LSB: Start Jenkins at boot time...
Jun 06 19:54:40 ip-172-31-3-216 jenkins[15989]: Correct java version found
Jun 06 19:54:40 ip-172-31-3-216 jenkins[15989]:  * Starting Jenkins Automation Server jenkins
Jun 06 19:54:40 ip-172-31-3-216 su[16030]: (to jenkins) root on none
Jun 06 19:54:40 ip-172-31-3-216 su[16030]: pam_unix(su-l:session): session opened for user je>
Jun 06 19:54:40 ip-172-31-3-216 su[16030]: pam_unix(su-l:session): session closed for user je>
Jun 06 19:54:41 ip-172-31-3-216 jenkins[15989]:    ...done.
Jun 06 19:54:41 ip-172-31-3-216 systemd[1]: Started LSB: Start Jenkins at boot time.

Jenkins in installed and running successfully.

Git Undo Changes (Reset / Revert / Rebase)



Tracked Files:- are files that have been created within repo's working directory and have been added to the repository using git add command. 

Untracked Files:- are files that have been created within your repo's working directory but have not yet been added to the repository's tracking index using the git add command.

$ echo "tracked" > ./tracked_file
$ echo "untracked" > ./untracked_file
$ git add ./tracked_file
warning: LF will be replaced by CRLF in tracked_file.
The file will have its original line endings in your working directory

$ git status
On branch sprint-2
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   tracked_file

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        untracked_file
$ git log --oneline
138da36 (HEAD -> sprint-2) index3 file added
e8bb55f (origin/master, master) Initial folder structure created.
027265e add readme to initial commit

$ git reset 138da36

$ git log --oneline
138da36 (HEAD -> sprint-2) index3 file added
e8bb55f (origin/master, master) Initial folder structure created.
027265e add readme to initial commit

$ git reset e8bb55f

$ git log --oneline
e8bb55f (HEAD -> sprint-2, origin/master, master) Initial folder structure created.
027265e add readme to initial commit

$ ls
docs/  index3.html  readme.md  src/  test/  tracked_file  untracked_file

$ git status
On branch sprint-2
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        index3.html
        tracked_file
        untracked_file

nothing added to commit but untracked files present (use "git add" to track)

Reset

$ git log --oneline
b764644 File with three lines
7c709f0 File with two lines
9ef9173 File with one line

$ git reset 9ef9173 (using an absolute commit SHA1 value 9ef9173)
or
$ git reset current~2 (using a relative value -2 before the "current" tag)

$ git log --oneline
9ef9173 File with one line


git reset --hard (This overwrites any local changes you haven't committed. In effect, it resets (clears out) the staging area and overwrites content in the working directory with the content from the commit you reset to. Before you use the hard option, be sure that's what you really want to do, since the command overwrites any uncommitted changes.)

Revert

The net effect of the git revert command is similar to reset, but its approach is different. Where the reset command moves the branch pointer back in the chain (typically) to "undo" changes, the revert command adds a new commit at the end of the chain to "cancel" changes.
$ git log --oneline
92eeac5 (HEAD -> sprint-2) added tracked_file
506d8ca added index3.html file.
e8bb55f (origin/master, master) Initial folder structure created.
027265e add readme to initial commit

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-2)
$ git revert HEAD
Removing tracked_file
[sprint-2 71fa892] Revert "added tracked_file"
 1 file changed, 1 deletion(-)
 delete mode 100644 tracked_file

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-2)
$ git log --oneline
71fa892 (HEAD -> sprint-2) Revert "added tracked_file"
92eeac5 added tracked_file
506d8ca added index3.html file.
e8bb55f (origin/master, master) Initial folder structure created.
027265e add readme to initial commit

Revert or reset?

Why would you choose to do a revert over a reset operation? If you have already pushed your chain of commits to the remote repository (where others may have pulled your code and started working with it), a revert is a nicer way to cancel out changes for them. This is because the Git workflow works well for picking up additional commits at the end of a branch, but it can be challenging if a set of commits is no longer seen in the chain when someone resets the branch pointer back.

Rebase

$ git log --oneline master
d0de868 (HEAD -> master) c5
e8bb55f (origin/master) Initial folder structure created.
027265e add readme to initial commit

$ git log --oneline sprint-2
9165990 (HEAD -> sprint-2) c4
df6bf21 c3
0374abc c2
764633c c1
71fa892 Revert "added tracked_file"
92eeac5 added tracked_file
506d8ca added index3.html file.
e8bb55f (origin/master) Initial folder structure created.
027265e add readme to initial commit

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-2)
$ git rebase master
Successfully rebased and updated refs/heads/sprint-2.

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-2)
$ git log --oneline master
d0de868 (master) c5
e8bb55f (origin/master) Initial folder structure created.
027265e add readme to initial commit

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-2)
$ git log --oneline sprint-2
af3a9c7 (HEAD -> sprint-2) c4
88dbaba c3
4854135 c2
7017d9a c1
cc47ff2 Revert "added tracked_file"
8719ecf added tracked_file
5d0fe72 added index3.html file.
d0de868 (master) c5
e8bb55f (origin/master) Initial folder structure created.
027265e add readme to initial commit

Jenkins Startup and Configuration

Steps to setup jenkins on ubuntu:- -After installation. check the jenkins services running on not on the server. sudo service jenk...