Jenkins CI/CD

Jenkins CI/CD

Creating an EC2 instance

Accessing the instance

Updating the machine

Installing Java

Installing Jenkins

curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null

This command downloads the Jenkins public key from the Jenkins package repository, and then pipes it to the 'tee' command with sudo privileges to write it to a file called 'jenkins-keyring.asc' in the '/usr/share/keyrings' directory. The '>' character is used to redirect the standard output to the file 'jenkins-keyring.asc'.

The '-fsSL' option is used with the 'curl' command to ensure that the output is silent and that the progress meter is disabled. It also follows any redirects and verifies the SSL certificate.

The purpose of this command is to add the Jenkins public key to the keyring so that it can be used to verify the authenticity of packages downloaded from the Jenkins package repository. This is an important security measure to ensure that the software packages are not tampered with during the download process.

Once the key is added to the keyring, it can be used by the package manager to verify the integrity of the Jenkins package repository packages before installing them.

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

This command adds the Jenkins package repository as a software source to the apt package manager configuration by creating a new file 'jenkins.list' in the '/etc/apt/sources.list.d/' directory, which contains the repository URL and uses the Jenkins public key added earlier to authenticate the packages downloaded from this repository.

The 'echo' command is used to print the repository information to the standard output, which is then piped to the 'tee' command with sudo privileges to write it to the file 'jenkins.list'. The '>' character is used to redirect the standard output to the file 'jenkins.list'.

The 'deb' keyword indicates that the following URL is a Debian package repository. The repository URL is "pkg.jenkins.io/debian binary/" which specifies that the repository is for binary packages.

The 'signed-by' option specifies the path to the Jenkins public keyring file that was created earlier. This option instructs the package manager to verify that the packages downloaded from this repository are signed with the Jenkins public key added to the keyring.

By running this command, the Jenkins package repository is added as a software source, allowing the user to install, update, and remove Jenkins packages using the apt package manager. This command ensures that the downloaded packages are authentic and not tampered with during the download process.

Enabling Jenkins port 8080 in the security group of the EC2 instance

Accessing Jenkins

Getting Administrator password

Installing suggested plugins

Create Jenkins user account

Jenkins is ready

Installing Docker in EC2 instance

Adding users ubuntu and jenkins to docker user group, and restarting docker

Installing docker pipeline plugins in jenkins

Creating a new pipeline job

Pipeline configuration

Building the job