[Jenkins] [git] jenkinsCI
0. Preface
Environment: linux (mint or others)
Objective: To automatically build a deb package
Task Description:
The project team needs an environment that can be automatically built. The main purpose is to automatically generate an installation package for the linux compiling environment. Three git libraries at the remote end of github and a package file on your server must be maintained.
1. for initial installation, go to the official website and select the latest version. 1. Go to the official website and click "Use Jenkins"
2. If you want to install Jenkins, click "Installing Jenkins"
3. The environment in this article is in Linux, and can be installed in a Unix Ubuntu environment, apt-get or Debian package.
4. Run the command to install Jenkins.
5. If You Want To Know (we suggest you know) What the installation has done, I will talk a lot about it below.
1. the default environment of Jenkins is installed under/var/lib/jenkins. This document uses this default folder. Of course, if you create a username for jenkins (this is required, it will be created by default), or it can be placed under/jenkins/home. 2. Deploy the Basic Environment of jenkins. Package or user who has added jenkins. To ensure seamless integration with java, Others. Jenkins puts some deployed files in the war package. If you are interested, try to customize your own things. However, Jenkins does not welcome you to do this. Tips: I found that Jenkins only uses these directories. /Var/lib/jenkins/var/log/jenkins/var/cache/jenkins
2. Important Concepts of Jenkins deployment 2.1
Before deployment, you must briefly understand jenkins.
Jenkins is an open-source software tool for continuous integration. Official Website: http://jenkins-ci.org /. That is to say, we borrowed Jenkins from the project to build software continuously. Just like entrusting others to do things, we can only monitor the purpose and result of things, and should not participate in the whole process of things. Through some preliminary deployment work, we found that Jenkins does not use the permissions of the System user during the CI process, but uses the permissions granted to Jenkins by the user (you) and uses Jenkins to represent everything. (Jenkins reads your configuration on the web, uses its local permissions, and uses jenkins's ssh permissions for remote access)
If you encounter Permission Deny or some ssh key problems in the configuration, it is because you do not understand the meaning of the previous section.
2.2 jenkins plug-in if you only need to deploy the java environment, congratulations! The system has installed all the plug-ins required by java in advance, this is because the predecessor of jenkins, huston, originally intended to deploy services for java. This is not the core of this article. For Git, a few things are required. Git plugin: this plug-in is used to synchronize git libraries. Multiply SCMs: Multiple SCM channels. One Git can be deployed for each SCM. People who have used Git libraries will ask, isn't Git plugins capable of synchronizing multiple libraries? Why use this. The answer is: although the Git library can synchronize multiple git libraries, it should be noted that the Git plug-in provides the branch option, however, it is for retrieving multiple branchs at the same time with each database. This does not conform to our principle. For deployment, you only need to call a branch in a Git library, so my mom needs this plugins.
2.3 jenkins system settings
If you open jenkins, open it in the default website localhost: 8080 as shown in the following figure. If jenkins has just been installed, nothing exists in MainView.
This article takes Chrome as an example. Because the system is pre-installed with Chinese characters, jenkins can identify and perform Chinese-based processing on most of the content. Careful people may have discovered that they have entered the logon interface in the upper right corner. If this is the first time they use it, they do not log on. They are set as anonymous users. However, it does not matter because the anonymous account will obtain all permissions before permission settings.
Click system management on the left.
Click "plug-in management" on the main interface, and then click "optional plug-ins" to find the plug-in to be played, and then click the Install button below. (PS: if you cannot find the installation button, you can zoom in and out the Browser display ratio. jenkins does not have a good research on the web interface)
3. Git plug-in
First, because Jenkins does not install the Git plug-in by default, You need to manually install the Git plug-in when you need git library synchronization.
3.1 install Git plugin 3.1.1 before installation
The git library is not installed, and git is not found in "Source code management". This is because jenkins does not install the git plug-in by default.
3.1.2 install git plugin
Go to System Management> Management plug-ins. Find the available plug-ins tab. In "filter" (a search window named filtering), you can enter Git on the keyboard for search.
We only click git plugin. jenkins will automatically add the dependent plug-in for us, as shown in.
Wait for the installation. If you select "restart Jenkins After installation" below, jenkins will be restarted; or you can enter "localhost: 8080/restart" in the browser to restart jenkins.
3.2 install the Multiple SCMs plugin
Although the Git plug-in can synchronize multiple git libraries, it can only synchronize the same branch of multiple git libraries. If your project needs to synchronize different branches of different libraries, this requires the Multiple SCMs plug-in.
Waiting for Installation
Effect after installation: click "Multiple SCMs" in source code management.
Click "AddSCM" and click Git to add multiple libraries.
3.3 install GitHub plug-in 3.3.1
Select "GitHub plugin" in the optional plug-ins. jenkins will also help you install other plug-ins on which it depends.
3.3.2 installation results
You can select "Build when a change is pushed to GitHub" during Build, and re-Build it when GitHub is updated.
3.4 create a Git Project
Create a project: (click New in the left menu)
Because it is to be synchronized with Git, no pre-configured project is selected (build a free-style software project free-style ).
Click "OK" and you will see that some things are not as full as below (this is because I have installed many other plug-ins to try, such as GerritRepo, however, this article has little to do with it. I will not introduce it here)
Select the "Git" option under "Source code management"
Click Add to Add A private key, enter your name at location A, open the private key generated by ssh with gedit or vi, and copy the content to location B.
If a red font is found after the key is added, Jenkins uses a simple clone command to check whether the private key is correctly added. (Use ssh to link the git Repository: git @ github: yourteam/yourproject /)
Here, you can use the git branch. The default branch is the master branch under the origin. On the interface, you can change it to any other branch under the origin.
Change source to remote upstream Source
Result
3.1 GerritRepo plug-in 3.1.1 is written at the beginning-the content of GerritRepo that needs to be done can be fully carried out in shell, and its existence is only used for concise code.
4. Shell & Repo (python) Jenkins can execute scripts, as long as you install plug-ins, php, python can run. However, this article finds that it is not ideal to execute the source statement in Jenkins, maybe because the sh THAT Jenkins fixed points to is bash, while the default in ubuntu is dash. The method used in this article is to write the statements you want to execute into a script, and comment out the sh used for execution in the first line of the script to avoid possible risks. 1. This article uses the absolute path for Directly Reading repo in shell during initialization. 2. Write an sh in the workspace and execute it in bash.
5. Others
5.1 build deployment we can set to execute build according to a certain cycle (similar to crontab, five parameters represent: hour, day, month, year, ten years)
5.2 if you do not set a build policy for a key setting, this problem may occur. Because the frequency is too high or the code is constantly updated, the build version number is squeezed too much in a short time.
The expected result is as follows: no matter how many builds, the build is retained in the last few days.
You only need to set the policy.