注意:需要有对应的权限,才能对GitLab进行配置
进入具体的项目 -> Settings -> CI/CD -> Runners -> Specific Runners
别人的是这样,我的不太一样,但是找还是能找到token在哪里
安装地址:
Install GitLab Runner | GitLab
注册教程:
Registering runners | GitLab
方式一:交互式注册
官方步骤:注册 Runner
- 注册过程中,你需要提供以下信息:
- GitLab服务器的URL:输入你的GitLab服务器的URL。 如:https://gitlab.com/
- Runner注册的Token:在GitLab项目的设置中,找到“CI/CD”>“Runners”页面,复制“Specific Runner Token”。找管理员要或者自己看(如果有权限的话)
- Runner的描述:输入一个描述此Runner的名称。
- Runner的标签:可以选择为Runner添加标签,用于在GitLab CI/CD配置中选择特定的Runner。这个标签tag很重要,需要记录下来。
- Runner的执行器:选择适合你的环境的执行器,如shell、docker、docker+machine等。此处填shell。
- 完成注册后,Runner将与GitLab服务器建立连接。
配置Runner:
- 注册成功后,可以在GitLab项目的设置中的“CI/CD”>“Runners”页面查看和配置Runner。
- 可以为Runner配置特定的标签、并发构建数、执行器选项等。
启动Runner:
- 在终端或命令提示符中,运行以下命令启动Runner:
sudo gitlab-runner start
注:我的使用上面命令会报错,使用sudo gitlab-runner run成功
[root@run01 ~]# gitlab-runner register
Runtime platform arch=amd64 os=linux pid=3293 revision=f767c145 version=15.3.3
Running in system-mode.
Enter the GitLab instance URL (for example, https://gitlab.com/):
http://192.168.170.133/
Enter the registration token:
GR1348941sUxNyye1qD4HcTSW-TMw
Enter a description for the runner:
[run01]: test
Enter tags for the runner (comma-separated):
build
Enter optional maintenance note for the runner:
this is d test
Registering runner... succeeded runner=GR1348941sUxNyye1
Enter an executor: custom, parallels, shell, docker-ssh+machine, docker, docker-ssh, ssh, virtualbox, docker+machine, kubernetes:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
Configuration (with the authentication token) was saved in "/etc/gitlab-runner/config.toml"
.gitlab-ci.yml里面的内容:
stages:
- build
variables:
ANDROID_APP_NAME: "flutterDemo" # Android 应用的名称
ANDROID_PACKAGE_NAME: "com.demo.flutter_demo" # Android 应用的包名
build_android_apk:
stage: build
script:
- flutter clean
- flutter build apk
tags:
- build
artifacts:
paths:
- build/app/outputs/flutter-apk/flutter_demo.apk
# only:
# - main # 配置只有 main 分支触发构建
记得android目录下配置kestore文件相关的内容。
打包成功的截图如下: