[英]Configure CircleCI for Maven project using Nexus repo
我正在為 java maven 項目使用外部Nexus
存儲庫,我正在嘗試配置 circleCI 配置。 起初我需要以某種方式說CircleCI
在構建期間查看環境變量以獲取憑據。 在grade
驅動的 java 項目中,無需任何額外配置,一切正常,但在maven
中,它表示無法訪問 nexus。 有人有這方面的經驗嗎? 這是我第一次配置 CircleCI
更新1:
為了授權,我在 CircleCI 組織設置頁面上為username
、 password
、 server url
和attributes
添加了 env 變量到上下文
我使用這個ORB,在那里我找到了我必須用作默認名稱的環境變量的名稱。
創建circleci
配置文件:
version: 2.1
orbs:
nexus-platform-orb: sonatype/nexus-platform-orb@1.0.28
workflows:
main:
jobs:
- nexus-platform-orb/nexusjob:
context: MyContext
並出現此錯誤:
Caught: java.io.FileNotFoundException: /tmp/workspace (Is a directory)
java.io.FileNotFoundException: /tmp/workspace (Is a directory)
at NexusPublisher.run(NexusPublisher.groovy:59)
Exited with code exit status 1
但是當我添加command
在里面創建文件並使用它時,我遇到了同樣的問題。 circleci 正在尋找哪個文件或目錄?
更新1:
我稍微更新了我的配置文件:
version: 2.1
orbs:
maven: circleci/maven@1.3.0
nexus-platform-orb: sonatype/nexus-platform-orb@1.0.28
jobs:
install-nexus:
executor: nexus-platform-orb/nexus-platform-cli
steps:
- checkout
- nexus-platform-orb/install
workflows:
main:
jobs:
- install-nexus
- nexus-platform-orb/nexusjob:
context: MyContext
workspace: tmp/workspace/
requires:
- install-nexus
結果我在運行這個作業時出錯:
/bin/sh: curl: not found
因為命令nexus-platform-orb/install
包含這一行:
curl -L
https://groovy.jfrog.io/artifactory/libs-release-local/org/codehaus/groovy/groovy-binary/<<
parameters.groovy-version >>/groovy-binary-<< parameters.groovy-version
>>.zip -o apache-groovy-binary.zip
但是添加命令安裝curl
給我另一個錯誤:
steps:
- checkout
- run: apk update && apk add curl curl-dev bash
- nexus-platform-orb/install
#!/bin/sh -eo pipefail
apk update && apk add curl curl-dev bash
ERROR: Unable to lock database: Permission denied
ERROR: Failed to open apk database: Permission denied
Exited with code exit status 99
而且我不知道如何修復它,因為我找到的唯一方法是將RUN root
添加到Dockerfile
。 但它不起作用。
更新2:
我花了一個多星期的時間來了解如何修復它並將我的解決方案作為答案發布。 希望它能為某人節省時間。
這個問題的解決方法是手動說明要使用什么文件來獲取憑據。
這就是我的config.yml
文件的樣子:
version: 2.1
orbs:
maven: circleci/maven@1.3.0
jobs:
build:
executor: maven/default
working_directory: ~/my-project
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "pom.xml" }}
- v1-dependencies-
- run:
name: Test
command: |
mvn -s ./settings.xml clean test
- save_cache:
paths:
- ~/.m2
key: v1-dependencies-{{ checksum "pom.xml" }}
workflows:
main:
jobs:
- build
我不再需要nexus
球了。 我使用maven
orb 作為executor
。 添加了命令mvn -s./settings.xml clean test
以運行測試並說明 nexus 憑證位於哪個文件中。
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
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>MYPROJECT</id>
<username>*****</username>
<password>*****</password>
</server>
</servers>
</settings>
並鏈接到我在pom.xml
文件中添加的Nexus
存儲庫:
<repositories>
<repository>
<id> MYPROJECT </id>
<name>*****</name>
<url>https://nexus.*****/</url>
</repository>
</repositories>
希望這個案例對某人有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.