Jenkins Declarative Pipeline
Jenkins Agents
Jenkins Declarative
Requirement
Jenkins Master (Install Java & Jenkins)
Jenkins Agent (Install Java)
Make SSH connection between Master and Agent
- Login to your AWS account
i) Create EC2 Instance for Jenkins Master
Install Java & Install Jenkins
sudo yum upgrade -y
yum install java-11-amazon-corretto-devel.x86_64 -y
sudo wget -O /etc/yum.repos.d/jenkins.repohttps://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --importhttps://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
sudo yum install jenkins -y
sudo systemctl daemon-reload
sudo systemctl enable jenkins
sudo systemctl start jenkins
Refer to my Previous Article:- https://cloud-devops.hashnode.dev/jenkins-installation-and-freestyle-project
ii) Create EC2 Instance for Jenkins Agent
Just Install Java (Jenkins Server installation is not required)
sudo yum upgrade -y
sudo yum install java-11-amazon-corretto-devel.x86_64 -y

Login/SSH to your Jenkins Master and create an SSH Key, using
ssh-keygenwhich will be used to connect to our Jenkins Agent/Nodei) Generate SSH Keys on Jenkins Master using (without password)
ssh-keygen -t ed25519
ii) Copy the Public Key from Jenkins Master
cat /home/ec2-user/.ssh/id_rsa.pubLogin to your Jenkins Agent/Node
i) Paste the public key copied from the above step and paste it on the file.ssh/authorized_keys

Connecting Jenkins Master and Jenkins Agent
Login to your Jenkins Dashboard > Manage Jenkins > Manage Nodes and Clouds > New Node
Node name: Jenkins-Agent
Type: Permanent Agent
Remote root directory: /home/ec2-user/jenkins-agent
Labels: dev-server [It should be unique]
Usage: Only build jobs with label expressions matching this node
Launch method: Launch agent via SSH
Host: Agent's Hostname or IP to connect.
Add Credentials: Jenkins Credentials Provider > Kind \> SSH Username with private key > Username ec2-user > Private Key - Enter directly (Include the private key created on the Jenkins Master - /home/ec2-user/.ssh/id_ed25519 )
Host Key Verification Strategy: Non verifying Verification Strategy








