Translate

Sunday, April 1, 2018

A personal CI system - building C program



Now we do have our CI system, how can we use it ?


If you have some code to compile with GCC, is possible to create a job in Jenkins to monitor it (on github) and every time the code is committed, have it updated on the server and compiled, notifying errors to the developer.







This can be done for many different environments.

The first thing to keep in mind is that the building environment MUST BE present on the server that is running Jenkins or one of the satellite server.
Jenkins allows to be connected to other machines, the satellite server, that can have specific settings for specific environments.

Here an example to gave an idea about what is possible to do with Jenkins.

GCC code


Well the simple thing is to manage a project with GCC.
Of course install all the necessary to compile your project on the server or on a satellite server.

Let's use my Wordhunt program as example.

Creating project

  1. be sure to be able to compile the code on the machine that hosts Jenkins.
    i.e. install compiler, libraries and everything is needed.
    For this simple basic program, just do :

    $ sudo apt-get update
    $ sudo apt-get upgrade
    $ sudo apt-get install build-essential
  2. Go on a browser (can be also on another machine) and log in to Jenkins
  3. Click on the New Item icon

  4. Assign the name of the project (for example Wordhunt) and select Freestyle project
    A new window will appear where to add the necessary data.
At that point we need to tell Jenkins where to find the code and what operations to do to compile it.
Here some suggestions for the first setting.
  • General tab
    • Set  project name
    • Add Description
    • Select github project
      • assign URL github project
      • assign display name
  • Source code management tab
    • Select git
    • Assign URL github project
    • Select credential (if credential exists, select it and proceed, if not click on Add button)
      • If add button :
        • Select the provider (should be only exist Jenkins)
        • Select the type, by default is username plus password.
          If you have ssh key select it
        • configure the credential
  • Build triggers
    • do nothing for now
  • Build Environment
    • do nothing for now
  • Build
    • Add Step
      • Execute shell
      • in the shell add :
        gcc wordhunt.c -o wh
  • Post build actions
    • do nothing for now
The credential to log in to github are necessary.

At this point is possible to build the code simply hitting the Build Now button on the Jenkins page for the project Wordhunt.
i.e. from the main page, click on the Wordhunt project.
On the left will appears a set of commands, among them : Build Now


Click on Build Now.
Jenkins will download the code form github and then compile it.

Following these instructions is possible to make Jenkins to do the build every time the project is pushed in github .

Note ! Of course in order to do so, you must have admin access to both github and Jenkins.


No comments:

Post a Comment