foreword
- This article mainly introduces how to install and deploy Jenkins, and realize automatic pulling of project code and automatic compilation process.
website
Download and install
- can download this
- Install java before installing jenkins
- yum search java|grep jdk
- yum install java-1.8.0-openjdk
- install jenkins
- java -jar jenkins.war
- After installation, go to the browser to access the corresponding port 8080, and the following page will appear
- After a few minutes, this interface will appear. Follow the prompts to copy the password
- Optionally install recommended plugins
- This piece may be slower, wait a little bit
- After waiting to enter this interface, we create an administrator account
- After the user is created, it will enter the jenkins page
Jenkins uses
- Start jenkins: java -jar jenkins.war
Preparation
- Before pulling the code, we need a git server. You can refer to my other article to build a GitLab server
- Then we need to install git on our jenkins machine
- yum install git
- install cmake
- It is recommended to go to the official website to download a newer version of cmake. The version of cmake installed with the command is lower, and an error may be reported.
pipeline
- The use of pipelines allows our tasks to be converted from ui manual operations to coding, which is more suitable for large-scale projects.
- full grammar
- pipeline : the entire pipeline
- agent : specifies the executor
- stages : all stages
- stage: a certain stage, there can be multiple
- steps : Each step in the stage, executable command
- helloword practical tutorial
-
Create a new item
-
Enter a task name and select the pipeline
-
Click on the task we created
-
select configuration
-
Fill out an official script case, save.
-
Click here to build now
-
You can see the build record below
-
Click in, select the console
-
You can see the printing of the entire execution process, and it has been executed successfully
-
Automate project builds
- Let's officially start to automatically pull code and compile
- Create a new task autoProject
- Choose the pipeline syntax here
- Select the fragment generator, select checkout here, that is, pull the code
- Then fill in the URL of your own project on the git server, and fill in the user name and password, and select the corresponding branch
- There is already a code on the gitlab server I built myself
- After filling in, select Generate Pipeline Script
- Copy and paste the script here
- Save and click build
- The build is complete, and the check mark indicates that the build is successful
- Look at the console print, it is successful
- Then go to the jenkins server, you can see that the code has been pulled down
- The automatic code extraction has been completed, and the next step is to implement automatic compilation. Write the compilation command directly in the script here
- Then click build, you can see success
- Go to the corresponding directory of the jenkins server, and you can see that there are programs that have been compiled successfully
- So far, we have implemented automated code fetching and compilation.