编程知识 cdmana.com

It's a good tool for continuous integration

http://xjjdog.cn Yes 200+ The original articles are classified in detail , Reading more smoothly , Welcome to collect .

original : Taste of little sister ( WeChat official account ID:xjjdog), Welcome to share , Reprint please keep the source . Any reprint without reservation of this statement is plagiarism .

“ The company's code assets , Put it inside the company . Prevent all invisible enemies , In a decadent way , Illegal encroachment on the interests of the company .”

SVN The s , It's gone forever , Now they all use the big ones git. Although there are GiteaGogs This is more lightweight git Code hosting platform , But now the most widely used , still gitlab.

build GitLab The process is not as simple as you think , Because it is Ruby Written , It's dependence again DB, It's dependence again Redis, And there are permission requirements . But this thing , Just once , The rest is to enjoy its functions .

Our usual development is , There are some requirements for continuous integration . Compared to deploying another jenkins, Use gitlab Of CI function , More silky .

1. An example

gitlab Realization ci The function is very simple , Directly at the top level of the warehouse , Create a .gitlab-ci.yml file , That's all right. . Most of our applications , Just configure such a file OK 了 .

Here's a vuepress Project ci file .

image: xjjdog.cn:5000/node:8.16.2

pages:
  tags:
    - pages
  cache:
    paths:
      - node_modules/

  script:
    - npm config set registry http://xjjdog.cn:8082/repository/npm-all/
    - npm install
    - npm run docs:build
  artifacts:
    paths:
      - public
  only:
    - master

The script above , Will submit code to master When , Automatic trigger execution . It will compile automatically node project , And release to the The release The place of .

On the left menu , You can find the relevant menu .

Click to enter , You can see the results of the execution and the operator and so on . code 、 All in one , Is it better than jenkins More intuitive ? To use ?

2. yaml file

So what we do is , It's all about yaml In the compilation of the document .

You'll find that , Whether you use docker-compose, Or use k8s, Even now Gitlab CI, You're essentially , It's just one. YAML The engineer .

YAML The engineer ! It is the representative of advanced productivity in the age of automation .

Let's see .gitlab-ci.yml Key concepts in . In fact, from it , We can see Makefile A little shadow of .

  • images/services This keyword can use Docker Image and service running Job
  • only only Match means match , For example, it only matches master And submit merge
  • stages One stages You can define multiple segments , Used to define a pipeline Different process nodes of (job)
  • stage It means a stages Children of , Usually used to give job Make a name . such as , The one above us pages, Namely job Name
  • cache cache It is used to define some directories and files that need to be cached between tasks
  • script The real order to execute , It could be a shell Script . If the script does not execute successfully , The process will end
  • before_script,after_script Used to define pre - and post scripts
  • variables Custom build variables
  • artifacts Use the generated resources as pipeline Successfully run the attachment upload , And in gitlab Download is available on the interactive interface . If you publish a static Directory , such as vuepress Compiled results , This is the most suitable one .
  • tags tags yes Job A mark of .

3. runner

This tags What does that mean ? When you first use it , It may be because of the wrong configuration , cause ci Unable to execute .

We're in the menu on the left , Find the whole picture settings, There's one in there, too CI/CD, One of them Runners Options , It's used to configure Runner Lock related tag Of .

in other words , You need to install one called GitLab Runner Things that are . It's the node where our tasks are actually performed .

After installation , You need to perform gitlab-runner register Sign in . Only when you see the words below , To prove your tags by pages Can perform the task of .

From the description above , We can see that , This gitlab-runner, It's distributed , We're space machines , Deploy multiple runner. therefore , Don't worry about it gitlab Server stress .

End

The task took too long , What should I do if I have to occupy resources all the time ?

have access to timeout To set the expiration time .

JobName:
  script: restart
  timeout: 30m

Why? gitlab It can be used as an ideal CI What about platforms? ?

Because on top of it , There's the original code . There are continuous integration tools . Yes Wiki, Even more advanced Pages, Also have .

For one git For projects , You can say what you want , It all has . And all the changes , Can be in an ordinary .gitlab-ci.yml Make changes in the document . so to speak gitlab It's a very sharp tool .

in fact , To make the operation smoother , We used gitlab Of rest api. By configuring the corresponding token, You can use Java Code , control gitlab All the actions of .

Integrate it into your company's tool library , It feels great .

Author's brief introduction : Taste of little sister (xjjdog), An official account that does not allow programmers to take turns. . Focus on infrastructure and Linux. Ten year structure , 10 billion traffic per day , Discuss the world of high concurrency with you , Give you a different taste . My personal wechat xjjdog0, Welcome to add friends , Further communication .

This article is from WeChat official account. - Taste of little sister (xjjdog) , author : Miss's dog

The source and reprint of the original text are detailed in the text , If there is any infringement , Please contact the yunjia_community@tencent.com Delete .

Original publication time : 2020-12-15

Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .

版权声明
本文为[xjjdog]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224122136501K.html

Scroll to Top