jenkins-vm
and provide same settings as below# on both devops-vm and jenkins-vm
# run the commands as needed
# now lets ping each other
# ping jenkins-vm ip from devops-vm
# this is the same name as the azure vm name you gave
ping -c5 jenkins-vm # ping -c5 10.0.1.5
# lets ping devops-vm from jenkins-vm
ping -c5 devops-vm
# now lets ssh devops-vm(client) from jenkins-vm(controller) so as to automate our work
# for this we need to install jenkins-vm with these commands first
sudo apt update
sudo apt install sshpass -y
# before running any sshpass commands lets first manually ssh to this vm
ssh ubuntu@devops-vm
# this will ask for yes confirm enter yes and then press ctrl+c we need this manual confirmation
# now lets view the ls -la for devops-vm from jenkins-vm this is first step of automation
sshpass -p 'Password@1234' ssh ubuntu@devops-vm 'sudo bash -c ls -la ~'
# so now we have confirmmation we can control devops-vm from jenkins-vm lets create a script on devops
# on devops-vm run this script to create a file that will build angular project and reload webserver
tee ~/angular_build_jenkins.sh << EOF > /dev/null
cd ~
git clone https://github.com/Professor-Paradox/angular_devops_demo.git
ls -la
cd angular_devops_demo
ls -la
sudo npm install -g @angular/cli
npm install .
ng build --configuration=production
cd ~; sudo cp -r ~/angular_devops_demo/dist/angular_devops_demo/* /var/www/html
sudo chmod -R +rx /var/www/html
sudo systemctl restart nginx
EOF
chmod +x ~/angular_build_jenkins.sh
# Now we can trigger the shell script from the jenkins-vm lets try manually with terminal
# after we can do the same with jenkins tool ui
/usr/bin/sshpass -p 'Password@1234' ssh -o StrictHostKeyChecking=no ubuntu@devops-vm 'sudo bash -c ~/angular_build_jenkins.sh'
# Install required java and jenkins for this jenkins-vm
sudo apt update
sudo apt install openjdk-17-jdk -y
java -version
# install latest jenkins
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt update
sudo apt install jenkins -y
# start the jenkins service on port 80 so that azure jenkins-vm port only needs to be opened on this
sudo systemctl enable --now jenkins
sudo systemctl restart jenkins
sudo systemctl status jenkins
sudo cat /var/lib/jenkins/secrets/initialAdminPassword