【问题标题】:CircleCi 2.0 working with project inside the subdirectoryCircleCi 2.0 在子目录中使用项目
【发布时间】:2018-05-28 16:15:24
【问题描述】:

我正在尝试将我的 springboot 教程项目与 CircleCi 集成。

我的项目位于 Github 存储库的子目录中,我从 CircleCi 收到以下错误。

Goal 需要一个项目来执行,但其中没有 POM 目录(/home/circleci/recipe)。请验证您调用了 Maven 从正确的目录。

我不知道如何告诉 circle-ci 我的项目在子目录中。我已经尝试了几件事,以及尝试在“食谱”中 cd,但它不起作用甚至感觉不对。

这是我的项目的结构:

Spring-tutorials
 |
 +-- projectA
 |    
 +-- recipe
 |   | +--pom.xml

这是我的config.yml

# Java Maven CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-java/ for more details
#
version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/openjdk:8-jdk

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/postgres:9.4

    working_directory: ~/recipe

    environment:
      # Customize the JVM maximum heap limit
      MAVEN_OPTS: -Xmx3200m

    steps:
      - checkout
      - run: cd recipe/; ls -la; pwd;

      # Download and cache dependencies
      - restore_cache:
          keys:
          - recipe-{{ checksum "pom.xml" }}
          # fallback to using the latest cache if no exact match is found
          - recipe-

      - run: cd recipe; mvn dependency:go-offline

      - save_cache:
          paths:
            - ~/recipe/.m2
          key: recipe-{{ checksum "pom.xml" }}

      # run tests!
      - run: mvn integration-test

【问题讨论】:

    标签: circleci circleci-2.0


    【解决方案1】:

    我设法解决了这个问题。我相信结合

        working_directory: ~/spring-tutorial/recipe
    

      - checkout:
          path: ~/spring-tutorial
    

    成功了。

    这是我的工作config.yml

    # Java Maven CircleCI 2.0 configuration file
    #
    # Check https://circleci.com/docs/2.0/language-java/ for more details
    #
    version: 2
    jobs:
      build:
        working_directory: ~/spring-tutorial/recipe
        docker:
          # specify the version you desire here
          - image: circleci/openjdk:8-jdk
    
          # Specify service dependencies here if necessary
          # CircleCI maintains a library of pre-built images
          # documented at https://circleci.com/docs/2.0/circleci-images/
          # - image: circleci/postgres:9.4
    
        environment:
          # Customize the JVM maximum heap limit
          MAVEN_OPTS: -Xmx3200m
    
        steps:
          - checkout:
              path: ~/spring-tutorial
    
          # Download and cache dependencies
          - restore_cache:
              keys:
              - recipe-{{ checksum "pom.xml" }}
              # fallback to using the latest cache if no exact match is found
              - recipe-
    
          - run: mvn dependency:go-offline
    
          - save_cache:
              paths:
                - ~/.m2
              key: recipe-{{ checksum "pom.xml" }}
    
          # run tests!
          - run: mvn integration-test
    

    【讨论】:

    • 为什么会这样?工作目录不设置工作目录吗?为什么还要checkout到sub_directory之前的文件夹?
    • 根据circleci for working_directory的文档:In which directory to run the steps.checkout是从一个git仓库检出源代码。
    • 此设置为我提供了您尝试签出的目录 (/home/circleci/spring-tutorial) 不是空的,也不是 git 存储库。那是因为 spring-tutorial 中存在 recipe 文件夹
    • @Ville 在我的例子中 spring-tutorial 是一个 git 存储库
    • 相同。但是当你定义 working_directory: ~/spring-tutorial/recipe 时,spring-tutorial 已经有一个文件夹(recipe),所以你不能在那里结帐,因为它不是空的,对吧?
    【解决方案2】:

    我有点困惑,所以我想进一步澄清一下

    构建子目录以定义您的工作空间的关键解决方案,在这种情况下,它的子文件夹将像这样定义

     working_directory: ~/repo/sub_folder
    

    结帐到

    - checkout:
         path: ~/repo
    

    变成这样

    # Javascript Node CircleCI 2.0 configuration file
    #
    # Check https://circleci.com/docs/2.0/language-javascript/ for more details
    #
    version: 2
    jobs:
      build:
        docker:
          # specify the version you desire here
          - image: circleci/node:7.10
    
          # Specify service dependencies here if necessary
          # CircleCI maintains a library of pre-built images
          # documented at https://circleci.com/docs/2.0/circleci-images/
          # - image: circleci/mongo:3.4.4
    
        working_directory: ~/repo/sub_folder
    
        steps:
          - checkout:
                path: ~/repo
    
          # Download and cache dependencies
          - restore_cache:
              keys:
                - v1-dependencies-{{ checksum "package.json" }}
                # fallback to using the latest cache if no exact match is found
                - v1-dependencies-
    
          - run: npm install
    
          - save_cache:
              paths:
                - node_modules
              key: v1-dependencies-{{ checksum "package.json" }}
    
          # run tests!
          - run: npm test
    

    【讨论】:

      【解决方案3】:

      如果有人尝试运行 npm 命令并且 cd 没有按预期工作,即:

      cd subdir && npm run command
      

      你可以使用 npm 的--prefix 选项。

      - run:
            name: Run start command in recipe folder
            command: npm --prefix ./recipe run start
      
      # then in same file
      - run:
            name: Run test command in app folder
            command: npm --prefix ./app run test
      

      【讨论】:

      • 我不使用 npm,因为它不是 javascript。
      猜你喜欢
      • 2018-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-03
      相关资源
      最近更新 更多