jenkins-from-zero-to-hero
install virtual machine Oracle VM
instal centos in that
get the ip from VM
install putty for ssh and connect jenkin machine
# First add repo to yum config manager
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# Use added repo to install and start docker
sudo yum install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
# Optional: Validate by run sample image
sudo docker run hello-world
#Copy the appropriate docker-compose binary from GitHub
sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
#NOTE: to get the latest version sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
#Fix permissions after download
sudo chmod +x /usr/local/bin/docker-compose
#Verify success
docker-compose version
how to quite from vi : hit : Escape then shift + : then wq then enter
create docker-compose.yml for jenkis image run
install suggested plugins
create admin user
create local DNS
C:\Windows\System32\drivers\etc
Getting started with Jenkins
Go to inside jenkin container and sh it
docker exec -it <container_name_or_id> <shell>
docker exec -it my_container bash
[jenkins@localhost jenkins-data]$ docker exec -ti jenkins bash
ienkins@2006d27ffa83 : /$
Add paramaters for before building your job with paramater
Add list parameters "choice parametrs"
Add basic logic and boolean parametrs
copying file from host to container
install plugin
upload mysql db backup into aws s3 using jenkins
# /bin/bash
DATE=$( date +%H-%M-%S)
BACKUP=db-$DATE .sql
DB_HOST=$1
DB_PASSWORD=$2
DB_NAME=$3
AWS_SECRET=$4
BUCKET_NAME=$5
mysqldump -u root -h $DB_HOST -p$DB_PASSWORD $DB_NAME > /tmp/$BACKUP && \
export AWS_ACCESS_KEY_ID=AKIAJRWZWY3CPV3F3JPQ && \
export AWS_SECRET_ACCESS_KEY=$AWS_SECRET && \
echo " Uploading your $BACKUP backup" && \
aws s3 cp /tmp/db-$DATE .sql s3://$BUCKET_NAME /$BACKUP
create docker file for creating image for ansible on top of jenkis running image
FROM jenkins/jenkins
USER root
RUN apt-get update && apt-get install python3-pip -y && \
pip3 install ansible --upgrade
USER jenkins