Lesson 6: Setting up the build and deployment jobs in Jenkins

You can learn about setting up the build and deployment jobs in Jenkins.

About this task

To set up a build and deployment jobs in Jenkins, you must create and configure the following jobs in Jenkins to automate the various stages for the pipeline:
  • Build_Input: Job for building the application.
  • Deploy_DEV: Job for deploying the application to the DEV environment.
  • Deploy_QA: Job for deploying the application to the QA environment.
  • Deploy_PROD: Job for deploying the application to the PROD environment.

Procedure

  1. Perform the following steps to create the Build_Input job:
    1. Sign in to your Jenkins application with valid login credentials.
    2. Click New Item.
    3. Type Build_Input in the Enter an item name field.
    4. Select Freestyle project.
    5. Click Ok.

      The Build_Input job is created and configuration page is displayed.

    6. In the General section, select This project is parametrised check box.
    7. Click Add parameter, and then select String Parameter from the list.
    8. Type the name for the String Parameter. For example, build number.
    9. Optional: Type the default value for the parameter in the Default Value field.
    10. Optional: Type the description for the parameter in the Description field.
    11. In the Source Code Management section, select Git.
    12. Type the URL of the GitHub repository in the Repository URL field. For example, https://github.com/username/reponame.
    13. In the Credentials section, click the drop down list, and then select credentials.

      If you are selecting the credentials for the first time, then you must add the credentials to Jenkins, and then select them from the Credentials section.

    14. In the Branch Specifier field, add the GitHub branch name. For example */main.
    15. In the Build Steps section, click Add build step, and then select Execute shell from the list.
    16. Type the following command in the Command field:
      echo '$BUILD_NUMBER'
    17. Click Save.
      You have created a Build_Input job in Jenkins.
  2. Perform the following steps to create the Deploy_DEV job:
    1. Sign in to your Jenkins application with valid login credentials.
    2. Click New Item.
    3. Type Deploy_DEV in the Enter an item name field.
    4. Select Freestyle project.
    5. Click Ok.

      The Deploy_DEV job is created and configuration page is displayed.

    6. In the General section, select This project is parametrised check box.
    7. Click Add parameter, and then select String Parameter.
    8. Type the name for the String Parameter. For example, build number.
    9. Optional: Type the default value for the parameter in the Default Value field.
    10. Optional: Type the description for the parameter in the Description field.
    11. In the Build Steps section, click Add build step and then select Execute shell from the list.
    12. Type the following command in the Command field:
      echo '$BUILD_NUMBER'
    13. Click Save.
      You have created a Deploy_DEV job in Jenkins.
  3. Perform the following steps to create the Deploy_QA job:
    1. Sign in to your Jenkins application with valid login credentials.
    2. Click New Item.
    3. Type Deploy_QA in the Enter an item name field.
    4. Select Freestyle project.
    5. Click Ok.

      The Deploy_QA job is created and configuration page is displayed.

    6. In the General section, select This project is parametrised check box.
    7. Click Add parameter, and then select String Parameter.
    8. Type the name for the String Parameter. For example, build number.
    9. Optional: Type the default value for the parameter in the Default Value field.
    10. Optional: Type the description for the parameter in the Description field.
    11. In the Build Steps section, click Add build step and then select Execute shell from the list.
    12. Type the following command in the Command field:
      echo '$BUILD_NUMBER'
    13. Click Save.
      You have created a Deploy_QA job in Jenkins.
  4. Perform the following steps to create the Deploy_PROD job:
    1. Sign in to your Jenkins application with valid login credentials.
    2. Click New Item.
    3. Type Deploy_PROD in the Enter an item name field.
    4. Select Freestyle project.
    5. Click Ok.

      The Deploy_PROD job is created and configuration page is displayed.

    6. In the General section, select This project is parametrised check box.
    7. Click Add parameter, and then select String Parameter.
    8. Type the name for the String Parameter. For example, build number.
    9. Optional: Type the default value for the parameter in the Default Value field.
    10. Optional: Type the description for the parameter in the Description field.
    11. In the Build Steps section, click Add build step and then select Execute shell from the list.
    12. Type the following command in the Command field:
      echo '$BUILD_NUMBER'
    13. Click Save.
      You have created a Deploy_PROD job in Jenkins.
    In this lesson, you have learned to setting up the build and deployment jobs in Jenkins.

What to do next

You can learn about adding a Jenkins application in the pipeline and configuring the build and deploy Jenkins jobs to the different environments in the pipeline. See Lesson 7: Adding a Jenkins application in the pipeline.