复制的GitLab项目触发Drone构建需手动审批,如何实现自动执行?
问题描述
从现有项目复制创建了新GitLab项目,提交代码后Drone能接收事件触发构建,但每次都需要手动确认、审批或驳回。已对比新旧项目的GitLab与Drone配置,二者完全一致。
当前Drone项目设置:
Project Settings:
Protected
Trusted
Auto cancel pull requestsProject Visibility:
Internal
Drone流水线模板如下:
kind: pipeline type: docker name: DEV-Build image_pull_secrets: - docker-config steps: - name: install image: enjo-docker-registry-registry.cn-hangzhou.cr.aliyuncs.com/deployment/node:16-alpine-yrm pull: if-not-exists commands: - yrm test `yrm current` - yarn - ${CMD:=''} volumes: - name: node_modules path: /drone/src/node_modules - name: build image: enjo-docker-registry-registry.cn-hangzhou.cr.aliyuncs.com/deployment/node:16-alpine-yrm pull: if-not-exists commands: - npm run build_dev - rm -rf /tmp/${DRONE_COMMIT} - mkdir /tmp/${DRONE_COMMIT} - mv dist/ /tmp/${DRONE_COMMIT}/ volumes: - name: tmp path: /tmp - name: node_modules path: /drone/node_modules volumes: - name: node_modules host: path: /var/lib/cache/node_modules - name: tmp host: path: /tmp/ trigger: branch: - dev event: - push - custom node: env: dev --- kind: pipeline type: exec name: DEV-Deploy clone: disable: true steps: - name: upload commands: - cd /tmp/${DRONE_COMMIT} - ossutil64 rm -rf oss://{{.input.app_name}}-dev/ - ossutil64 cp -rf ./dist/ oss://{{.input.app_name}}-dev/ trigger: branch: - dev event: - push - custom node: env: dev depends_on: - DEV-Build --- kind: pipeline type: docker name: TEST-Build image_pull_secrets: - docker-config steps: - name: install image: enjo-docker-registry-registry.cn-hangzhou.cr.aliyuncs.com/deployment/node:16-alpine-yrm pull: if-not-exists commands: - yrm test `yrm current` - yarn - ${CMD:=''} volumes: - name: node_modules path: /drone/src/node_modules - name: build image: enjo-docker-registry-registry.cn-hangzhou.cr.aliyuncs.com/deployment/node:16-alpine-yrm pull: if-not-exists commands: - npm run build_test - rm -rf /tmp/${DRONE_COMMIT} - mkdir /tmp/${DRONE_COMMIT} - mv dist/ /tmp/${DRONE_COMMIT}/ volumes: - name: tmp path: /tmp - name: node_modules path: /drone/node_modules volumes: - name: node_modules host: path: /var/lib/cache/node_modules - name: tmp host: path: /tmp/ trigger: branch: - test event: - push - custom node: env: test --- kind: pipeline type: exec name: TEST-Deploy clone: disable: true steps: - name: upload commands: - cd /tmp/${DRONE_COMMIT} - ossutil64 rm -rf oss://{{.input.app_name}}-test/ - ossutil64 cp -rf ./dist/ oss://{{.input.app_name}}-test/ trigger: branch: - test event: - push - custom node: env: test depends_on: - TEST-Build
解决方法
以下是排查和实现自动构建的具体方向:
1. 开启Drone项目的Auto-Start设置
进入Drone项目的设置页面,确认Auto-Start选项已勾选。该选项关闭时,即使收到GitLab的推送事件,流水线也会处于等待手动启动的状态。
2. 匹配GitLab分支保护与Drone权限
- 检查GitLab中
dev、test分支是否为保护分支,若是,需确保Drone的服务账号拥有该分支的推送权限,且Drone项目的Trusted模式已正确生效(当前已开启,但需确认权限映射无异常)。 - 核对GitLab项目的Webhook配置,确保「Push Events」已勾选,且Webhook的URL、Secret与旧项目完全一致。
3. 排查审批规则配置
- 查看Drone项目的全局流水线规则,确认是否添加了针对特定分支/事件的强制审批要求。
- 检查Drone服务器的全局配置,是否启用了
DRONE_REQUIRE_APPROVAL环境变量,若该变量设为true,所有项目都会强制要求手动审批。
4. 重新同步项目关联
- 在Drone中删除该项目,重新从GitLab导入,确保项目关联过程中权限、设置完全同步。
- 手动触发一次构建,观察是否仍需审批,同时查看Drone构建日志,确认触发条件是否匹配YAML中的
trigger规则(分支、事件类型是否符合要求)。
内容的提问来源于stack exchange,提问作者Yu Fang Cheng
相关产品推荐
相关产品推荐

