?? Day 3 ??: Website Development with Jenkins Job on AWS-EC2 and use Build periodically.
Vaibhav Jain
DevOps | Cloud | AWS | CI/CD | Red Hat Linux | Git/Github | Docker | Ansible | Terraform | Kubernetes | Networking
Jenkins Build Triggers:
In Jenkins, a build trigger is a mechanism that initiates the execution of a Jenkins job or pipeline. Triggers are used to start builds automatically based on various events or conditions.
Manual Build Trigger
Build Now: You can start a build whenever you want by clicking the “Build Now” button on the Jenkins dashboard for a specific job. This is helpful for one-time or on-demand builds.
Scheduled Build Trigger
Build Periodically: You can set up builds to run at specific times using the “Build periodically” option in the job settings. Use cron syntax to set the schedule. For example, to run a build every night at 2:00 AM, use 0 2 * * *.
SCM (Source Code Management) Trigger
Poll SCM: If you’re using a version control system like Git or Subversion, you can set the job to check the repository for changes. When it finds changes, Jenkins will start a build automatically. This is called the “Poll SCM” trigger.
Webhooks Trigger
Webhooks: Many version control systems and services support webhooks, which notify Jenkins when there are code changes. Jenkins listens for these notifications and starts builds in response.
Dependency Build Trigger
Build after other projects are built: You can set up a job to start after one or more other jobs finish successfully. This is useful for building pipelines or making sure certain steps are completed before starting a build.
Parameterized Build Trigger
Trigger builds with parameters: You can create builds that start with specific parameters. This allows you to customize builds based on input values.
Pipeline Trigger
Pipeline Trigger: If you’re using Jenkins Pipelines (written in a Jenkinsfile), you can use different triggers within the pipeline script. For example, you can set up a webhook trigger, a schedule trigger, or a manual trigger within the script.
Remote API Trigger
Remote API: You can start Jenkins builds from other scripts or applications using Jenkins' REST API.
Plugin-Based Triggers
Jenkins has many plugins that offer extra trigger options. For example, the “GitHub Webhook” plugin lets Jenkins listen to GitHub events and start builds accordingly.
so in this, we have to create our job for Jenkins, and after this:
so we create the Git Repository the name is index_repo:
we can check in the machine whether the Git is installed or not:
rpm -q git
for the checking of the httpd package we have to put the command in the machine:
rpm -q httpd
so we have to start this service with Jenkins:
so we go into the build step>execute shell of the job and put all commands for the httpd service:
after the build the job I see that there is no error. So I successfully run the build:
so now we successfully built the job we can see the files in workspace of the Jenkins:
so now the main thing is where these files which we see in the Jenkins web UI where are stored?
so the answer that this file is coming from the Git-hub repo and stored in the machine folder and the location of the file is:
领英推荐
/var/lib/jenkins/
so now we have to check whether the index.html file is gone on the machine or not:
so the default location of the index.html files is:
ls /var/www/html/
as we can see at the location there is no file of HTML:
so here is where we send the file from the Jenkins default location whatever it is [(./index.html)=it goes itself and searches the file] and sends to the file location that we put of the main machines the file location like this(/var/www/html/).
so we put this command in the Jenkins<Build step :
sudo cp ./index.html /var/www/html/
after we put the command in Jenkins's job' build step and after this, we apply and run the build.
so after this, we successfully built the job:
so we have to check that our website is deployed or not on the server:
so we put the machine public on the Google and let's see what we see:
So hurray ???? we deploy the website by using Jenkins on AWS-EC2.
now we can see that the index.html file is on the machine:
so we also commit to this:
so here we can see the Build Periodically that helps in the automation of the website health check and updates that we put after is running or updating and checks the website so we can know early time about our website automatically that our website is working properly:
so every minute:
After this setup, we can see that our builds are running automatically in every second.
Here on the left, we can see that our 3rd build automatically starts and after one minute our fourth build will also start.
so the checks we update our index.html file we see that our builds are working:
we change in our file and add one more line:
the most important thing we have to Commit this change:
and push the repo in the main file:
come and now see the results:
You can see that the last line is automatically added.
so here is our #Day-3 of the Jenkins Journey. Today we deploy a web and change in with the Build periodically option.
so bye??, let's meet tomorrow on Day 4 with the new and exciting Jenkins article.
#DevopsWithVaibhav