1. What does gitlab CI / CD do
The development language frequently used in the field of embedded software development is
C language, in large-scale project development, we often have the requirements of format review and compilation review. If you can help
GitLabReviewing the format and compilation of the platform implementation code will greatly improve the standardization of the combined code, control the impact of the new code on the original code, and improve the overall quality of the code.
This paper will discuss how to use hand-in-hand teaching
CIHelp us do code format review and compilation review.
2. Gitlab CI / CD quick build
2.1 VC code setting
VS CodeSet to auto format on save.
- Place in the code root directory
.clang-formatFile is a configuration file for code formatting and format checking, which can be downloaded from
Clang-FormatDownload the official website to the template and adjust it according to your own needs. See the syntax for detailslink。 Edit it
.clang-formatThis file, placed in the root directory of the code, is
VS CodeAfter editing the code, execute the save operation, and the saved file will automatically format the code according to the format specification of the file.
.clang-format-ignoreFile is used to configure
CIFiles or folders that ignore code format checking in.
2.2 gitlab configuration
Premise: you are already
GitLabThere is a code warehouse, and you are the owner of the warehouse
How to let gitlab CI / CD do code format review and compilation review for us? To sum up, there are five points:
- Warehouse root configuration
- Script for configuring code review in the warehouse
clang-formatFormat review tools and compiled scripts;
- Configure a for compilation
GitLabA public warehouse is configured
GitLabA personal warehouse is configured
Runner(usually this machine);
.gitlab-ci.ymlCan be understood as pipeline file, using
.gitlab-ci.ymlThe document describes what you want to do. This requirement includes code pulling, code format review and code compilation. hold
.gitlab-ci.ymlPut it in the root directory of the remote branch every time you
RunnerWill be triggered automatically
CI pipeline, do it
.gitlab-ci.ymlWhat is described in the pipeline file.
RunnerWell understood, it is a machine used to run format review and compilation review of warehouse code. Generally, the public warehouse will be a server and the personal warehouse will be a local machine.
3. Specific configuration process
The file describes the code update method and two methods
check, conduct code format review; the other one
build, do code compilation.
scriptIt describes the execution of commands, that is, in
RunnerCommands executed in.
tagsThe description is
RunnerIdentification of, and
RunnerThe settings at the time of registration are consistent, which is used to
CI pipelineThe host was successfully found in.
Command for code format review:
python .workflow/ci/format_check/run-clang-format.py --clang-format-executable .workflow/ci/format_check/clang-format.exe -r components/。 Invoked in the command
clang-format.exeExecute the file and specify the folder path to check.
Commands for code compilation:
.workflow/ci/build/build_keil.bat, called the compilation script under the specified path.
3.2 Script and tool configuration
In the code warehouse
.workflow > ci Place the script for format review in different folders under the path
clang-formatFormat review tool and compilation script:
run-clang-format.pyFormat review scripts and
3.3 Compile project
In the code warehouse
.workflow > ci > projects_compilePlace one or more for compilation under the path
MDKProject, covering all codes through the configuration of one or more projects.
3.4 Configure runner for public warehouse
First, we need to find one
- Create a folder somewhere in the system, for example:
- download64 bitor32 bitBinaries and place them in the folder you created. Rename to
Windows PowerShell, enter
./gitlab-runner.exe registerCommand: required for intermediate stage
RunnerYour identification needs to be consistent with
RunnerThe identity of is consistent, otherwise the specified cannot be found
TokenFrom the code warehouse
RunnerAfter, you can
F:\OneOS_Operate_System\GitLab-RunnerSee under folder
config.tomlFile, open and modify one place:
shell = "pwsh"by
shell = "powershell"
Windows PowerShellExecute commands in sequence
.\gitlab-runner.exe startYou can start
After successful startup, you can see
RunnerThere is one more device in the next. The device ID is
tagsIt should be
3.5 Personal warehouse configuration runner
RunnerBuilt on the local machine, the configuration method is basically the same as that of the public warehouse
RunnerConfiguration method, the only difference is registration
TokenIt needs to be obtained from the personal warehouse. Entered at registration
RunnerIdentification with public warehouse
RunnerThe identification shall be consistent.
3.6 Runner environment configuration
RunnerSuccessful format review command:
python .workflow/ci/format_check/run-clang-format.py --clang-format-executable .workflow/ci/format_check/clang-format.exe -r components/And code compilation commands:
.workflow/ci/build/build_keil.batYou also need to
RunnerMake a certain configuration (both the server and the local computer must):
Add system environment variable（
MDKBe sure to add)
3.7 Restart runner
./gitlab-runner.exe restartTo restart
RunnerFor the first time, both the server and the machine should be restarted by executing this command
Runner。 After success, you do not need to execute this command. Even if the host is restarted, it can be used normally
RunnerThere is no need to do anything else.
pushOr from personal warehouse to public warehouse
MergeThe request will trigger the pipeline and conduct code format review and compilation for the whole code warehouse. If any item fails, it will not be integrated into the public warehouse.
4. Focus on && contact