其他分享
首页 > 其他分享> > Drone构建失败,一次drone依赖下载超时导致构建失败的爬坑记录

Drone构建失败,一次drone依赖下载超时导致构建失败的爬坑记录

作者:互联网

Once upon a time, birds were singing in the forest, and people were dancing under the trees, It's so peaceful

1 发生

1.1 Drone简介

Drone by Harness™ is a modern Continuous Integration platform that empowers busy teams to automate their build, test and release workflows using a powerful, cloud native pipeline engine.

1.2 Context

因为xxx所以Drone构建的所依赖的maven私服停服了,构建界面哀鸿遍野,于是更换构建镜像,换上新的仓库地址,森林仿佛回到了之前的平静

随着新的新的镜像的更换,在构建记录中会偶尔出现构建失败的情况,build的时间也加长了一点,起初并没有很关注这个问题,直到有一天这个问题一直repeat,版本一直推不上去,开发的功能迟迟不能提测,各种压力扑面而来

1.3 现象描述

drone在执行build节点突然中断,没有任何报错日志,第一反应是Drone工具有问题,于是立马在公司的IM上密相关负责人,他们定位日志说应当是私服拉取超时,可能是私服那边做了熔断,这个私服全公司都在用,构建失败需要联系私服那边人一起定位去看,跨部门协同让人头大

drone构建是加了缓存的,且之前一直没有问题,为什么突然就不行了,而且build日志中为什么一直在打印下载依赖的日志,于是果断的放弃跨多部门协同这条路,转身来定位一下问题出现的原因

2 定位

2.1 Drone配置如下

# 工作空间
workspace:
   base: /app
   path: code

pipeline:
   #  恢复cache
   restore_cache:
      image: appleboy/drone-sftp-cache
      server: 172.31.xx.xx
      port: xx
      username: xxx
      password: xxx
      path: /home/mavencache/cache
      restore: true
      mount:
         - /app/.m2/
   build:
      # 这里是更换的新的镜像
      image: hub.xxx.com/xxx/cicd-xx:1.1
      when:
         event:
            - push
         branch: [dev*, release*, emergency, hotfix*, master]
      commands:
         # 初始化目录,防止没有
         - mkdir -p /app/.m2/
         - export NAME=web-center-v4
         - export APP_ID=5ee0528eb090259fe0056ac0
         - echo $NAME > NAME
         - echo $(jx-release-version)-$DRONE_COMMIT_BRANCH.$DRONE_BUILD_NUMBER > VERSION
         - cat VERSION
         - export COMMIT_ID=$DRONE_COMMIT
         - export COMMIT_BRANCH=$DRONE_COMMIT_BRANCH
         - export BUILD_NUMBER=$DRONE_BUILD_NUMBER
         - cd charts  && sh upload.sh && cd ..
         - mvn versions:set -DnewVersion=$(cat VERSION)
         - mvn package -DskipTests
         - echo $(cat VERSION) > .tags

2.2 调试

drone构建的节点是可以执行linux命令的,于是在commonds下加了一句 mvn -X,输出截取如下

……
[DEBUG] Reading global settings from /opt/apache-maven-3.5.3/conf/settings.xml
[DEBUG] Reading user settings from /root/.m2/settings.xml
[DEBUG] Reading global toolchains from /opt/apache-maven-3.5.3/conf/toolchains.xml
[DEBUG] Reading user toolchains from /root/.m2/toolchains.xml
[DEBUG] Using local repository at /root/.m2/repository
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for /root/.m2/repository
……

可以看到 settings.xml 的位置以及 localRepository 的位置,这个和我们配置的workspace不一致
我们配置的是 /app/.m2,怎么会走默认的路径?于是 cat /root/.m2/settings.xml 走起

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository  -->
</settings>

这里问题已经比较明显的,这个settings.xml在本地Repository这一块是默认配置,所以所有的缓存都没有生效

2.3 尝试解决

尝试1:手动编写了一个setting文件,增加命令 cp settings.xml /root/.m2/,提交构建速度恢复正常

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
   <!-- 设置本地仓库的地址 -->
  <localRepository>/app/.m2/</localRepository> 
</settings>

尝试2:修改缓存挂载路径为/root/.m2/,提交构建速度恢复正常

2.4 问题回头看

一个疑问,这样的修改虽然能够解决,但是为什么之前都没有问题?于是我镜像改为之前的,再次执行cat /root/.m2/settings.xml

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <!-- localRepository
     | The path to the local repository maven will use to store artifacts.
     |
     | Default: ${user.home}/.m2/repository  -->
    <localRepository>/app/.m2</localRepository>
</settings>

这下问题实锤了,是新镜像问(的)题(锅),生成的settings.xml没有读取workspace的配置信息

3 解决方案

不细说了,找领导修改构建镜像,祝我好运

标签:xml,settings,drone,失败,m2,DEBUG,构建,root
来源: https://www.cnblogs.com/surging-dandelion/p/14385820.html