Day 25 of #90DaysOfDevOps

Day 25 of #90DaysOfDevOps

Automating Job Builds

  1. Build Periodically

    This option is used to run the jobs at scheduled time.

    This field follows the syntax of cron (with minor differences). Specifically, each line consists of 5 fields separated by TAB or whitespace:

    MINUTE HOUR DOM MONTH DOW

    | MINUTE | Minutes within the hour (0–59) | | --- | --- | | HOUR | The hour of the day (0–23) | | DOM | The day of the month (1–31) | | MONTH | The month (1–12) | | DOW | The day of the week (0–7) where 0 and 7 are Sunday. |

    In our configuration, we've specified five stars with a single whitespace, indicating that the job runs every minute.

    Apply and Save the job. After applying and saving the job configuration, wait for a minute to witness the automatic job initiation, denoted in the console output as "Started by timer."

  2. Poll SCM

    Jenkins will check if there are any new commits to the repository mentioned the "Source Code Management" section at periodic time. If there is a new commit then only Jenkins will build/run the job.

    Similar to the "Build Periodically" option, our configuration here also specifies five stars with a single whitespace, indicating that Jenkins connects with the GitHub repository every minute to check for new commits.

    We can see that the build has "Started by an SCM change".

    Note that this is going to be an expensive operation for CVS, as every polling requires Jenkins to scan the entire workspace and verify it with the server.

  3. GitHub hook trigger for GITScm polling

    This option is widely used for automating the build process, as it initiates the job only upon receiving a trigger from GitHub following a successful commit, ensuring that your Jenkins job only runs when necessary, thus optimizing resources and improving efficiency.

    This integration between Jenkins and GitHub allows for seamless continuous integration and delivery (CI/CD) pipelines, ensuring that your builds are automatically triggered as soon as changes are pushed to your GitHub repository. This not only saves time but also helps maintain the integrity and reliability of your development process by ensuring that builds are always based on the latest changes.

    How to setup webhook in GitHub?

    1. Navigate to your GitHub repository settings.

    2. Select "Webhooks"

    3. Click on "Add webhook" and provide your credentials.

  1. Add your Jenkins URL in the "Payload URL" field as: http://public-ip:8080/github-webhook/.

  2. Choose content type as application/json.

  3. Select desired events to trigger the webhook (e.g., "Send me everything").

  4. Click on "Add webhook"

  1. In Jenkins, select "GitHub hook trigger for GITScm polling" in the build triggers options, then apply and save.

  1. Now, any changes made to your GitHub repository will automatically trigger the job build.

  2. You'll notice in the console output that the build is initiated with the message "Started by GitHub push by basavaraj-teli."

Congratulations! You've successfully automated the build process.