我正在尝试将我的springboot
教程项目与CircleCi集成。
我的项目位于 Github 存储库内的子目录中,我从 CircleCi 收到以下错误。
目标需要执行项目,但其中没有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
我设法解决了这个问题。我相信结合
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
我有点困惑,所以我想进一步澄清一下
构建子目录以定义工作空间的关键解决方案,在这种情况下,它的子文件夹,因此它将像这样定义
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
如果有人尝试运行 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
我的代码库有一个web
目录,整个Web应用程序都驻留在该目录下,包括package.json
,package-lock.json
,Webpack配置等。我的应用程序必须在web
目录中构建,并从在其下创建的dist
提供服务。我希望 CircleCI 在安装所需的依赖项后在此web
子目录中运行测试。接受的答案在 CircleCI 2.1 配置中对我不起作用。这是我尝试过的config.yml
version: 2.1
jobs:
test:
docker:
- image: cimg/node:16.15.1
# Added working directory pointing to `web`
working_directory: ~/app/web
steps:
- checkout:
# Checking out to the parent directory
path: ~/app
- restore_cache:
keys:
- npm-packages-{{ checksum "package-lock.json" }}
- npm-packages-
- run:
name: Installing packages
command: npm install
- run:
name: Run tests
command: npm run test
- save_cache:
paths:
- node_modules
key: npm-packages-{{ checksum "package-lock.json" }}
它给了我错误
Directory you are trying to checkout to is not empty and not a git repository
最终对我有用的是利用run
步骤支持的working_directory
属性。更新后的 CI 配置如下所示。
version: 2.1
jobs:
test:
docker:
- image: cimg/node:16.15.1
# Kept the working directory as such
working_directory: ~/app
steps:
# Kept checkout as such
- checkout
- restore_cache:
keys:
# Restoring cache using web/package-lock.json
- npm-packages-{{ checksum "web/package-lock.json" }}
- npm-packages-
# Running npm install in the web directory using working_directory
# property of the run step
- run:
name: Installing packages
working_directory: ~/app/web
command: npm install
# Running npm test in the web directory using working_directory
# property of the run step
- run:
name: Run tests
working_directory: ~/app/web
command: npm test
- save_cache:
paths:
- node_modules
# Saving cache using web/package-lock.json
key: npm-packages-{{ checksum "web/package-lock.json" }}