This is the 23rd day of my participation in the August More Text Challenge.More challenges in August
preface
Before, we had many branches of the project, and then we had to merge and package them according to different branches. Sometimes when the project is urgent, the code will be packaged and deployed, but forget to submit the code to GitLab; As a result, other colleagues failed to package your code in gitLab because the code you packaged before was not submitted.
This scenario is very common, and you don’t always remember to commit to GitLab, merge code, and then package the deployed process.
How should this be solved?
That’s right, introducing what we’re going to talk about today, gitLab configuration automation deployment.
After configuring automatic deployment, normally we don’t need to worry about the package deployment link, we just need to submit the code to gitLab, gITLab will automatically help us package.
Gitlab configuration automated deployment
Before configuration, let’s understand a few concepts:
- Gitlab sets up automated deployment through its CI (Continuous integration) /CD (Continuous delivery) options.
- You need to create a new file under the gitlab project root
.gitlab-ci.yml
This file is the automatic deployment configuration file, through which we can install dependencies/package/deploy operations. - for
.gitlab-ci.yml
Gitlab will notify configured tasksgitlab-runner
This software performs the build task. - Each Git submission corresponds to a Pipeline, which consists of a job.
.gitlab-ci.yml
How many missions are there (stages
), which represents the number of jobs in a Pipeline
process
Download gitlab – runner
I am Windows version, create a folder (I named gitlab-Runner), download the Gitlab-Runner installation package, select your compatible version (64-bit or 32-bit), and download the installation package to that directory.
Create a powerShell/ or CMD file in this directory.
Install and register gitlab-Runner
\gitlab-runner. Exe install, CMD run gitlab-runner install.
Once installed, a config.toml will be generated and the gitlab-Runner configuration will be stored in this file.
Then execute the.\gitlab-runner. Exe register
Fill in the following steps:
- Enter the GitLab instance URL (for example, gitlab.com/): Enter your GitLab address
- Enter the registration token: This token is your GitLab project token, click
setteings-> CI/CD ->Runners settings
See,Specific Runners
There is a token marked red at the bottom. - Enter a description for the runner: Description of the runner
- Enter tags for the Runner (Comma-Separated): I’m going to skip over this, but if you fill this out,
.gitlab-ci.yml
The task inside must also have this tag, otherwise it will not be executed. - Enter an executor: custom, ssh, virtualbox, docker-ssh+machine, kubernetes, docker+machine, docker, docker-windows, docker-ssh, parallels, Shell: Select an executor, in this case I chose
shell
, it isgitlab-runner
Which actuators to run on (actuators you can also choosedocker
Etc.) - Registered successfully
You can then see a display of registered Runners under Setteings -> CI/CD ->Runners Settings ->Specific Runners
run
. \ gitlab – runner. Exe start starts
Other instructions:
.\gitlab-runner.exe stop
suspended.\gitlab-runner.exe status
The state of the runner
submit
My.gitlab-ci.yml file configuration (note that this file should be in the project root directory) :
# before_script: # Since every stage is independent and dependencies need to be reinstalled, choose to cache dependencies here
cache:
key: ${CI_COMMIT_REF_SLUG}
untracked: true
paths:
- node_modules/ # cache node_modules
before_script:
- yarn install --frozen-lockfile --prefer-offline
stages:
- install
- build
install:
stage: install
tags:
- test
script:
- yarn
install:
stage: build
tags:
- test
script:
- yarn run build
Copy the code
And then we tested it in GitLab
After submitting the code, the build automatically starts, as shown below
In the operation of the
Building a successful
Problems encountered
config.toml
After the file is generated, the runner’s configuration will be stored in it, because I choose to execute itshell
, but the shell it generates is"pwsh"
, so change topowershell
conclusion
The above is the summary of gITLab configuration automation deployment, we can follow my tutorial to deploy, there are questions welcome to comment communication.
Thank you for reading.