The goal is to set up a complete CI/CD pipeline that:
sudo apt update
sudo apt install openjdk-11-jdk -y
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update
sudo apt install jenkins -y
sudo systemctl start jenkins
sudo systemctl enable jenkins
sudo yum install -y java-1.8.0-openjdk
wget https://download.sonatype.com/nexus/3/latest-unix.tar.gz
tar -xvzf latest-unix.tar.gz
mv nexus-3* nexus
sudo mv nexus /opt/
sudo useradd nexus
sudo chown -R nexus:nexus /opt/nexus
sudo su - nexus
/opt/nexus/bin/nexus start
sudo yum install -y java-11-openjdk
sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.0.0.45539.zip
sudo unzip sonarqube-9.0.0.45539.zip -d /opt/
sudo mv /opt/sonarqube-9.0.0.45539 /opt/sonarqube
sudo useradd sonar
sudo chown -R sonar:sonar /opt/sonarqube
sudo su - sonar
/opt/sonarqube/bin/linux-x86-64/sonar.sh start
pipeline {
agent any
environment {
SONARQUBE_URL = 'http://<SonarQube-IP>:9000'
NEXUS_REPO = 'http://<Nexus-IP>:8081/repository/maven-releases/'
}
stages {
stage('Checkout Code') {
steps {
git branch: 'main', url: 'https://github.com/your-repo.git'
}
}
stage('Code Quality Analysis') {
steps {
withSonarQubeEnv('SonarQube') {
sh 'mvn sonar:sonar'
}
}
}
stage('Build and Test') {
steps {
sh 'mvn clean package'
}
}
stage('Publish Artifact to Nexus') {
steps {
sh 'mvn deploy -DaltDeploymentRepository=nexus::default::${NEXUS_REPO}'
}
}
stage('Deploy to AWS using CodeDeploy') {
steps {
sh 'aws deploy create-deployment --application-name MyApp --deployment-group-name MyDeploymentGroup --s3-location bucket=my-s3-bucket,key=my-app.zip,bundleType=zip'
}
}
stage('Slack Notification') {
steps {
slackSend(channel: '#devops-alerts', message: 'Deployment Completed!')
}
}
}
}
provider "aws" {
region = "us-east-1"
}
resource "aws_s3_bucket" "artifact_bucket" {
bucket = "my-ci-cd-artifacts"
}
resource "aws_instance" "jenkins_server" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.medium"
key_name = "my-key"
security_groups = ["jenkins-sg"]
tags = {
Name = "Jenkins-Server"
}
}
terraform init
terraform apply -auto-approve
- name: Install Apache hosts: all become: true tasks: - name: Install Apache yum: name: httpd state: present - name: Start Apache service: name: httpd state: started
ansible-playbook -i inventory.ini deploy.yml
version: 0.0 os: linux files: - source: / destination: /var/www/html/ hooks: AfterInstall: - location: scripts/restart-apache.sh timeout: 300 runas: root
This project helps you master CI/CD automation using AWS DevOps tools. You’ve now: