Creating the Pipeline

In the previous section, we created a project and added sample code files plus some unit tests. However, we never integrated our project into Jenkins to confirm that our code actually works. We will create a pipeline in this section, adding a few basic stages to it to run our tests.

  1. Go to the Jenkins dashboard and select New Item.
  2. Enter an appropriate name for the project and select Pipeline for the project type.
  3. In the project configuration, under the General tab, select GitHub project and enter the appropriate URL.
  1. Under the Build Triggers section, select the GitHub hook trigger for GITScm polling, which will help us automatically trigger builds on our pipeline whenever a commit is pushed to GitHub. This configuration will only work with a hosted Jenkins server and configured GitHub webhook on the repository.

The final configuration of the project is creating our pipeline.

  1. Under the pipeline section, select Pipeline script under Definition.
  1. In the script section of the configuration, add the following snippet of code:

Your final pipeline script configuration should look like this:

  1. Press Apply to save the configuration so far before Jenkins logs you out, which may result in some data loss.
  2. Select Save to persist your configuration and redirect you back to the project dashboard.
  3. Select Build Now on the left-hand menu to build your project. Since we have no commits to push, we will manually trigger a build.
  1. On the project dashboard, after running our build, the Stage View shows up.

We can see the stages we configured earlier on in our pipeline and the amount of time it took to run each step. By hovering over and clicking each time length, we can view the logs and exactly which commands ran for that stage. For instance, the output for the first stage is as follows:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.2.15