How to build a continuous integration system using Jenkins and Docker
13/06/2017 - JARUZAFA
13/06/2017 - JARUZAFA
[SHOWTOGROUPS=4,20]
In this entry I will explain how to leverage Docker technology to build a continuous integration system that will monitor your source code repository, build your product, pass the tests, audit automatically the code with SonarQube and leave the binaries ready to download.
In a classic scenario we would have a few virtual machines doing all those tasks, but with Docker you can go to a scenario where we distribute the tasks in different containers instead of virtual machines, resulting in a much lighter environment, easier to scale and easier to migrate. Before I continue, I want to make one thing clear , in this blog post I will not explain you how to “dockerize” applications, I will do it another day
Our continuous integration environment will be composed by:
или Зарегистрируйсяwith the Docker QuickStart Terminal console. Commands are the same if you use Docker to other platforms.
A master to rule them all
If you’ve ever used Jenkins, you should know that ther is usually a master node that contains tasks configurations and it’s on charge of launching the tasks or “jobs”. The are several “agents” nodes (also known as “slaves”) which run those tasks.
Well, let’s go for it …. In the console where you have Docker installed type:
docker pull jenkinsci/jenkins: lts
This will download the image with the latest version of LTS (Long Time Support) Jenkins.
Start the container:
docker run --name jenkins_master -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkinsci/jenkins:lts
A little explanation on this command:
The initial password will be visible in the console or in the file /var/jenkins_home/secrets/initialAdminPassword
Just type the key and continue with the Setup process:
For now, choose the default option “Install suggested plugins”
OK, you’re almost done, you just need to create an administrator user:
Now you should see the Welcome screen:
Ahh, our old “Hello World” friend
To do a quick test to see if Jenkins works, go to “New item” to create a new job:
At section “Build“, please click in “Add build step” and select “Execute Shell”
And type:
echo Hello World
And now “Save” and “Build Now“. After a while you will see the build number:
[/SHOWTOGROUPS]
In this entry I will explain how to leverage Docker technology to build a continuous integration system that will monitor your source code repository, build your product, pass the tests, audit automatically the code with SonarQube and leave the binaries ready to download.
In a classic scenario we would have a few virtual machines doing all those tasks, but with Docker you can go to a scenario where we distribute the tasks in different containers instead of virtual machines, resulting in a much lighter environment, easier to scale and easier to migrate. Before I continue, I want to make one thing clear , in this blog post I will not explain you how to “dockerize” applications, I will do it another day
Our continuous integration environment will be composed by:
- A Для просмотра ссылки Войди
или Зарегистрируйся“master” container which will orchestrate the tasks - One or more “agents” containers (also known as “slaves”), which will carry out the tasks
- An automatic code analyzerin a SonarQube container
A master to rule them all
If you’ve ever used Jenkins, you should know that ther is usually a master node that contains tasks configurations and it’s on charge of launching the tasks or “jobs”. The are several “agents” nodes (also known as “slaves”) which run those tasks.
Well, let’s go for it …. In the console where you have Docker installed type:
docker pull jenkinsci/jenkins: lts
This will download the image with the latest version of LTS (Long Time Support) Jenkins.
Start the container:
docker run --name jenkins_master -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkinsci/jenkins:lts
A little explanation on this command:
- Puts a name to the container: jenkins_master
- Publishes ports 8080 and 50000
- Mounts a volume into the folder var/jenkins_home of the HOST (external to the container), where the configuration and the results of the tasks are stored. If you do this way, if the container is destroyed, information will not be lost.
The initial password will be visible in the console or in the file /var/jenkins_home/secrets/initialAdminPassword
Just type the key and continue with the Setup process:
For now, choose the default option “Install suggested plugins”
OK, you’re almost done, you just need to create an administrator user:
Now you should see the Welcome screen:
Ahh, our old “Hello World” friend
To do a quick test to see if Jenkins works, go to “New item” to create a new job:
At section “Build“, please click in “Add build step” and select “Execute Shell”
And type:
echo Hello World
And now “Save” and “Build Now“. After a while you will see the build number:
[/SHOWTOGROUPS]