当前位置: 首页 > 工具软件 > Drone-CI > 使用案例 >

自动化构建:gitlab gitlab-run ,maven的缓存 和 gitea drone drone-run

郝玄天
2023-12-01
#Started.gitlab-ci.yml

stages:          # List of stages for jobs, and their order of execution
  - build

maven-build:
  when: manual
  stage: build
  image: maven:3.6.3-jdk-8
  script:
    - mvn -Dmaven.test.skip=true -P dev clean package
    - cp target/*.jar /app/build #这里是maven:3.6.3-jdk-8容器文件夹
  artifacts:
    paths: 
      - target/*.jar


#docker-run 配置
# [[runners]]
  # name = "docker-runner"
  # url = "http://192.168.241.128:6080/"
  # token = "KLfUs5WySxrNozxmTddF"
  # executor = "docker"
  # [runners.custom_build_dir]
  # [runners.cache]
    # [runners.cache.s3]
    # [runners.cache.gcs]
    # [runners.cache.azure]
  # [runners.docker]
    # tls_verify = false
    # image = "alpine:latest"
    # pull_policy = "if-not-present"
    # privileged = false
    # disable_entrypoint_overwrite = false
    # oom_kill_disable = false
    # disable_cache = false
    # volumes = ["/cache","/data/qqq-gitlab/maven:/root/.m2","/data/qqq-gitlab/builds:/app/build"] 关键这里挂在目录配置
    # shm_size = 0

这里是    gitea drone 文件名.dron.yml

kind: pipeline
type: docker
name: default
steps:
  - name: build-package # 流水线名称
    image: maven:3.8-openjdk-8 # 定义创建容器的Docker镜像
    volumes: # 将容器内目录挂载到宿主机,仓库需要开启Trusted设置
      - name: maven-cache
        path: /root/.m2 # 将maven下载依赖的目录挂载出来,防止重复下载
      - name: maven-build
        path: /app/build # 将应用打包好的Jar和执行脚本挂载出来
    commands:
      - mvn -Dmaven.test.skip=true -P dev clean package
      - cp target/*.jar /app/build/*.jar
      
volumes: # 定义流水线挂载目录,用于共享数据
  - name: maven-build
    host:
      path: /data/app/maven/build # 从宿主机中挂载的目录
  - name: maven-cache
    host:
      path: /data/app/maven/cache

总结:用到 image: maven:3.8-openjdk-8镜像构建的,代码和编译后代码都在此容器中,所以要通过配置映射到宿主机中好操作!

 类似资料: