Automatic Build From the GitHub Repository via Jenkins

In this post, I am going to create an automatic build trigger via Jenkins Jobs. Basically, after pushing a new piece of code to the target repository/branch, Jenkins will create a new build package from the updated source code. If Jenkins has not been installed yet in your environment, I had explained “How to install Jenkins” in one of the previous articles. If you want to read it, you can access it from here.

Note: The sample project for this article is using dotnet core as a framework. If you prefer a different framework than dotnet core, It is going to be required to change the build step. (might be more steps than one.)

Let’s get started! After logging into Jenkins, I click the Create a Job link on the dashboard. The screenshot for the dashboard is like the following.

In the first step, I have to choose an item name and item type. I am going to continue with the Freestyle project option for the sample project. The screenshot for first step is like the following.

The project is ready for the configuration. If the repository is not public, you need to enter the GitHub user authentication information. I am going to continue with the public repository but you can find details for the private repository usage from the following steps.

As a first configuration step, I am going to configure the repository from the Configure -> Source Code Management tab. It is on the left sidebar. I choose Git for the sample and enter the repository URL. Like I said before, If the repository is a private one, you have to enter your authorization information. If you do not, Jenkins shows an error under the URL section. To pass this error, It is enough to click the Add button and insert the GitHub user information. The sample screenshots for this step are like the following.

The next step is to configure the Build Trigger. I want to check the repository every minute for this sample. To do this, I am going to choose the Poll SCM option and enter * * * * * as a value. It is possible to continue with other options as well but for this article, I preferred to continue with this option.

The GitHub configuration is completed. The next step is Build section configuration. When I update the GitHub repository, this build section is going to work and Jenkins will prepare a new build from the project. I am going to type CLI commands in this step. For the sample project, the following definition is enough.

Basically, when I push a new piece of code, Jenkins is opening the Tailspin.SpaceGame.Web folder in the GitHub project and running the next 3 commands to create a new package from the updated source. In the Project Root -> Last Build, It is possible to see all processes for the last build. The screenshot for the Latest build button and the sample running are like the following.

It is possible to access published project via the console output. The sample for this article is like the following.

I hope this article can be helpful to understand How to Create a Jenkins Job. Next time, I am thinking of continuing this article and adding the publish section to this job. To add any additional information or any mistake you can contact with me via this post or article[at]cinarr[dot]com

See you in the next posts 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *