Jenkins from configuration to actual combat (1) - Realize automatic construction of C/C++ projects

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
    insert image description here
  • 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
    insert image description here
  • After a few minutes, this interface will appear. Follow the prompts to copy the password
    insert image description here
  • Optionally install recommended plugins
    insert image description here
  • This piece may be slower, wait a little bit
    insert image description here
  • After waiting to enter this interface, we create an administrator account
    insert image description here
  • After the user is created, it will enter the jenkins page
    insert image description here

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
      insert image description here

    • Enter a task name and select the pipeline
      insert image description here

    • Click on the task we created
      insert image description here

    • select configuration
      insert image description here

    • Fill out an official script case, save.
      insert image description here

    • Click here to build now
      insert image description here

    • You can see the build record below
      insert image description here

    • Click in, select the console
      insert image description here

    • You can see the printing of the entire execution process, and it has been executed successfully
      insert image description here

Automate project builds

  • Let's officially start to automatically pull code and compile
  • Create a new task autoProject
  • Choose the pipeline syntax here
    insert image description here
  • Select the fragment generator, select checkout here, that is, pull the code
    insert image description here
  • 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
    insert image description here
  • There is already a code on the gitlab server I built myself
    insert image description here
  • After filling in, select Generate Pipeline Script
    insert image description here
  • Copy and paste the script here
    insert image description here
  • Save and click build
    insert image description here
  • The build is complete, and the check mark indicates that the build is successful
    insert image description here
  • Look at the console print, it is successful
    insert image description here
  • Then go to the jenkins server, you can see that the code has been pulled down
    insert image description here
  • 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
    insert image description here
  • Then click build, you can see success
    insert image description here
  • Go to the corresponding directory of the jenkins server, and you can see that there are programs that have been compiled successfully
    insert image description here
  • So far, we have implemented automated code fetching and compilation.

Guess you like

Origin blog.csdn.net/new9232/article/details/131876870