I’m attempting to push my artifacts to Nexus (3.18.0-01, docker) from a GitLab Runner, but I’m getting the following error:
Failed to execute goal org.sonatype.plugins:nxrm3-maven-plugin:1.0.2:deploy (default-deploy) on project my-project: Get tag was unsuccessful (401 response from server): Unauthorized -> [Help 1]
I followed GitLab guide, which works, and changed the relevant portions to Nexus.
https://docs.gitlab.com/ee/ci/examples/artifactory_and_gitlab/
Here are my maven details using the Sonatype guide (Repository Manager for Maven Plugin):
Tag properties:
<properties>
<nxrm3.staging.tag>${project.artifactId}-${project.version}</nxrm3.staging.tag>
</properties>
Distribution element:
<distributionManagement>
<repository>
<id>my-nexus</id>
<name>my-nexus</name>
<url>${env.MAVEN_REPO_URL}/repository/maven-releases</url>
</repository>
<snapshotRepository>
<id>my-nexus</id>
<name>my-nexus</name>
<url>${env.MAVEN_REPO_URL}/repository/maven-snapshots</url>
</snapshotRepository>
</distributionManagement>
Plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nxrm3-maven-plugin</artifactId>
<version>1.0.2</version>
<extensions>true</extensions>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<serverId>my-nexus</serverId>
<nexusUrl>${env.MAVEN_REPO_URL}</nexusUrl>
<repository>maven-releases</repository>
<tag>${nxrm3.staging.tag}</tag>
</configuration>
</plugin>
[project_folder]/.m2/settings.xml:
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd"
xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<servers>
<server>
<id>my-nexus</id>
<username>${env.MAVEN_REPO_USER}</username>
<password>${env.MAVEN_REPO_PASS}</password>
</server>
</servers>
</settings>
MAVEN_REPO_URL, MAVEN_REPO_USER and MAVEN_REPO_PASS are set in GitLab. The user was added to the admin
role to eliminate that as the authorization problem, but that didn’t work. Nexus is running in a docker container and exposed on port 8081, so it’s URL is set to http://myipaddress:8081
.
For completeness, here is my .gitlab-ci.yml
:
image: maven:3-jdk-8
variables:
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
cache:
paths:
- .m2/repository/
- target/
build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS compile
tags:
- maven
test:
stage: test
script:
- mvn $MAVEN_CLI_OPTS test
tags:
- maven
deploy:
stage: deploy
script:
- mvn $MAVEN_CLI_OPTS deploy
tags:
- maven
only:
- master
I checked the Log Viewer and there is nothing in there. Below is the entire post build/test output:
[INFO]
[INFO] --- maven-jar-plugin:3.1.0:jar (default-jar) @ my-project ---
[INFO] Building jar: /builds/util/my-project/target/my-project-1.0.0.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ my-project ---
[INFO] Installing /builds/util/my-project/target/my-project-1.0.0.jar to /builds/util/my-project/.m2/repository/com/myis/license/my-project/1.0.0/my-project-1.0.0.jar
[INFO] Installing /builds/util/my-project/pom.xml to /builds/util/my-project/.m2/repository/com/myis/license/my-project/1.0.0/my-project-1.0.0.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ my-project ---
[INFO] Skipping artifact deployment
[INFO]
[INFO] --- nxrm3-maven-plugin:1.0.2:deploy (default-deploy) @ my-project ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.264 s
[INFO] Finished at: 2019-08-06T19:50:45Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonatype.plugins:nxrm3-maven-plugin:1.0.2:deploy (default-deploy) on project my-project: Get tag was unsuccessful (401 response from server): Unauthorized -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
And the full debugging info. I did BASE64 decode the Basic auth string, and it did have my username:password
correctly set:
[INFO] --- nxrm3-maven-plugin:1.0.2:deploy (default-deploy) @ my-project ---
[DEBUG] Configuring mojo org.sonatype.plugins:nxrm3-maven-plugin:1.0.2:deploy from plugin realm ClassRealm[extension>org.sonatype.plugins:nxrm3-maven-plugin:1.0.2, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[DEBUG] Configuring mojo 'org.sonatype.plugins:nxrm3-maven-plugin:1.0.2:deploy' with basic configurator -->
[DEBUG] (f) artifact = com.agois.license:my-project:jar:1.0.0
[DEBUG] (f) attachedArtifacts = []
[DEBUG] (f) mavenSession = org.apache.maven.execution.MavenSession@426e505c
[DEBUG] (f) nexusUrl = http://myipaddress:8081
[DEBUG] (f) offline = false
[DEBUG] (f) packaging = jar
[DEBUG] (f) pluginArtifactId = nxrm3-maven-plugin
[DEBUG] (f) pluginGroupId = org.sonatype.plugins
[DEBUG] (f) pomFile = /builds/util/my-project/pom.xml
[DEBUG] (f) repository = maven-releases
[DEBUG] (f) serverId = ago-nexus
[DEBUG] (f) tag = my-project-1.0.0
[DEBUG] -- end configuration --
[DEBUG] CookieSpec selected: default
[DEBUG] Re-using cached 'basic' auth scheme for http://myipaddress:8081
[DEBUG] Connection request: [route: {}->http://myipaddress:8081][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
[DEBUG] Connection leased: [id: 0][route: {}->http://myipaddress:8081][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
[DEBUG] Opening connection {}->http://myipaddress:8081
[DEBUG] Connecting to /myipaddress:8081
[DEBUG] Connection established 172.17.0.4:45720<->myipaddress:8081
[DEBUG] Executing request GET /service/rest/v1/tags/my-project-1.0.0? HTTP/1.1
[DEBUG] Target auth state: CHALLENGED
[DEBUG] Proxy auth state: UNCHALLENGED
[DEBUG] http-outgoing-0 >> GET /service/rest/v1/tags/my-project-1.0.0? HTTP/1.1
[DEBUG] http-outgoing-0 >> Host: myipaddress:8081
[DEBUG] http-outgoing-0 >> Connection: Keep-Alive
[DEBUG] http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_222)
[DEBUG] http-outgoing-0 >> Accept-Encoding: gzip,deflate
[DEBUG] http-outgoing-0 >> Authorization: Basic REMOVED
[DEBUG] http-outgoing-0 >> "GET /service/rest/v1/tags/my-project-1.0.0? HTTP/1.1[\r][\n]"
[DEBUG] http-outgoing-0 >> "Host: myipaddress:8081[\r][\n]"
[DEBUG] http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
[DEBUG] http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_222)[\r][\n]"
[DEBUG] http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
[DEBUG] http-outgoing-0 >> "Authorization: Basic REMOVED[\r][\n]"
[DEBUG] http-outgoing-0 >> "[\r][\n]"
[DEBUG] http-outgoing-0 << "HTTP/1.1 401 Unauthorized[\r][\n]"
[DEBUG] http-outgoing-0 << "Date: Tue, 06 Aug 2019 20:35:00 GMT[\r][\n]"
[DEBUG] http-outgoing-0 << "Server: Nexus/3.18.0-01 (OSS)[\r][\n]"
[DEBUG] http-outgoing-0 << "X-Content-Type-Options: nosniff[\r][\n]"
[DEBUG] http-outgoing-0 << "WWW-Authenticate: BASIC realm="Sonatype Nexus Repository Manager"[\r][\n]"
[DEBUG] http-outgoing-0 << "Content-Length: 0[\r][\n]"
[DEBUG] http-outgoing-0 << "[\r][\n]"
[DEBUG] http-outgoing-0 << HTTP/1.1 401 Unauthorized
[DEBUG] http-outgoing-0 << Date: Tue, 06 Aug 2019 20:35:00 GMT
[DEBUG] http-outgoing-0 << Server: Nexus/3.18.0-01 (OSS)
[DEBUG] http-outgoing-0 << X-Content-Type-Options: nosniff
[DEBUG] http-outgoing-0 << WWW-Authenticate: BASIC realm="Sonatype Nexus Repository Manager"
[DEBUG] http-outgoing-0 << Content-Length: 0
[DEBUG] Connection can be kept alive indefinitely
[DEBUG] Authentication required
[DEBUG] myipaddress:8081 requested authentication
[DEBUG] Authorization challenge processed
[DEBUG] Authentication failed
[DEBUG] Clearing cached auth scheme for http://myipaddress:8081
[DEBUG] Connection [id: 0][route: {}->http://myipaddress:8081] can be kept alive indefinitely
[DEBUG] Connection released: [id: 0][route: {}->http://myipaddress:8081][total kept alive: 1; route allocated: 1 of 2; total allocated: 1 of 20]