Vadym
Vadym

Reputation: 163

Configure CircleCI for Maven project using Nexus repo

I'm using external Nexus repository for java maven project and I trying to config circleCI config. At first I need to somehow say CircleCI to look into env variables for credentials during build. In grade driven java projects all going fine without any extra configs, but in maven it says that can't have access to nexus. Have anybody experience with it? It's my first time configuring CircleCI

UPD1:

For authorisation I added env variables for username, password, server url and attributes to context on CircleCI Organization Settings page

I using this ORB and there I have found the names of env variables I have to use as default names.

Created circleci config file:

version: 2.1

orbs:
  nexus-platform-orb: sonatype/[email protected]

workflows:
  main:
    jobs:
      - nexus-platform-orb/nexusjob:
          context: MyContext

And have this error:

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

But when I added command to create file inside and used it, I steel have the same problem. For a which file or directory circleci is looking for?

UPD1:

I a bit updated my config file:

version: 2.1

orbs:
  maven: circleci/[email protected]
  nexus-platform-orb: sonatype/[email protected]

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

As a result I have an error running this job:

/bin/sh: curl: not found

Because command nexus-platform-orb/install contains this line:

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

But adding command installing curl gives me one another error:

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

And I have no idea how to fix it, because only way I found is to add RUN root to the Dockerfile. But it not works.

UPD2:

I spent more than week to understand how to fix it and posted my resolution as an answer. Hope it will save time for someone.

Upvotes: 1

Views: 754

Answers (1)

Vadym
Vadym

Reputation: 163

The resolution of this problem is to manually say what exactly file to use for getting credentials.

This is how my config.yml file looks after all:

version: 2.1

orbs:
  maven: circleci/[email protected]

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

I do not need nexus orb anymore. I used maven orb for an executor. Added command mvn -s ./settings.xml clean test to run tests and says in which file nexus credentials are.

settings.xml file:

<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>

And link to Nexus repository I added in pom.xml file:

<repositories>
    <repository>
        <id> MYPROJECT </id>
        <name>*****</name>
        <url>https://nexus.*****/</url>
    </repository>
</repositories>

Hope this case will help someone.

Upvotes: 0

Related Questions