jenkins throwing access denied - maven

I am trying to run a basic maven project through jenkins for artifact I am using myMavenRepo,I have done the configuration in pom.xml for myMavenRepo.write and myMavenRepo.read and added settings.xml file in .m2 folder below is the setting.xml
'''
<settings>
<servers>
<server>
<id>myMavenRepo.read</id>
<username>myMavenRepo</username>
<password>${yourHttpAuthReadPassword}</password>
</server>
<server>
<id>myMavenRepo.write</id>
<username>myMavenRepo</username>
<password>${yourHttpAuthWritePassword}</password>
</server>
</servers>
</settings>
'''
I have done below configuration for myMavenRepo.read and myMavenRepo.write in pom.xml
'''
<project>
...
<repositories>
<repository>
<id>myMavenRepo.read</id>
<url>${myMavenRepo.read.url}</url>
</repository>
</repositories>
...
</project>
'''
'''
<project>
...
<distributionManagement>
<repository>
<id>myMavenRepo.write</id>
<url>${myMavenRepo.write.url}</url>
</repository>
</distributionManagement>
...
</project>
'''
while running the job I am specifying "clean deploy" command but its giving error saying
Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project demo: Failed to deploy artifacts: Could not transfer artifact com.example:demo:jar:0.0.1-20200502.130925-1 from/to myMavenRepo.write
Access denied to:
Please let me know how to fix it

Related

How can I configure GITLAB CI with NEXUS?

I want to create a pipeline with Gitlab CI to compile a maven project.
First, I create a .m2 folder in root of my project and I add the settings.xml config file.
My project look like :
Project
- module1
- module2
- module3
- pom.xml
- .m2
-setting.xml
In the settings file I do this :
<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>nichefactory-releases</id>
<username>user</username>
<password>password</password>
</server>
<server>
<id>nichefactory-snapshots</id>
<username>user</username>
<password>password</password>
</server>
</servers>
<profiles>
<profile>
<id>nexus</id>
<properties>
<env>dev</env>
<flex.debug>true</flex.debug>
</properties>
<repositories>
<repository>
<id>nichefactory</id>
<name>NicheFactory Repository</name>
<url>http://my-nexus:8081/nexus/content/groups/public</url>
</repository>
</repositories>
</profile>
</profiles>
</settings>
In my pom.xml I have this repository :
<distributionManagement>
<!-- Publish the versioned releases to nexus -->
<repository>
<id>nichefactory-releases</id>
<name>Niche Factory Repository (RELEASE)</name>
<url>http://my-nexus:8081/nexus/content/repositories/releases</url>
</repository>
<!-- Publish the snapshot release to nexus -->
<snapshotRepository>
<id>nichefactory-snapshots</id>
<name>Niche Factory Repository (SNAPSHOTS)</name>
<url>http://my-nexus:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
And in my .gitlab-ci.yml I have :
image: maven:latest
variables:
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
build:
stage: build
script:
- mvn compile -P dev -DskipTests
When I push this config to gitlab, the pipeline start with a failure message :
Failure to find apps:pom:version in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM # line 4, column 10
It seems that gitlab try to connect to the default maven repository and not to my nexus.
How can I tell gitlab to call the nexus repository and not the default repository ?
MAVEN_CLI_OPTS is not an official MAVEN environment variable, but the recommended way to store repeating options. you can even see this in the GitLab Example
Just try:
build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS compile -P dev -DskipTests

Github action push java artifact to github repo

I have a Github repo project using GitHub actions with a docker file used to build the SpringBoot Java project.
I want to download packages from the Github repo for custom artifacts from GitHub repo and also be able upload artifact to it.
So I followed the link Configuring Apache Maven for use with GitHub Packages by adding the section to a settings.xml file:
<activeProfiles>
<activeProfile>github</activeProfile>
</activeProfiles>
<profiles>
<profile>
<id>github</id>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>github</id>
<name>GitHub OWNER Apache Maven Packages</name>
<url>https://maven.pkg.github.com/OWNER/REPOSITORY</url>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>github</id>
<username>USERNAME</username>
<password>${GITHUB_TOKEN}</password>
</server>
</servers>
</settings>
To publish the package from the dockerfile build I added the following to my pom.xml:
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub OWNER Apache Maven Packages</name>
<url>https://maven.pkg.github.com/OWNER/REPOSITORY</url>
</repository>
</distributionManagement>
The following is the content of my dockerfile:
FROM adoptopenjdk/maven-openjdk10 as build
WORKDIR /app
ADD pom.xml /app/pom.xml
ADD src /app/src
ADD settings.xml /root/.m2/settings.xml
RUN ["mvn", "clean", "install", "deploy"]
Is it possible to deploy from the dockerfile to Github repo? Somehow the deploy piece does not seem to work. I have tried few times but not sure what's wrong with my sections.
Currently this is my error in my docker build:
Could not transfer metadata
com.chg.sa:demo-sa-java-service:1.0-SNAPSHOT/maven-metadata.xml
from/to github (https://maven.pkg.github.com/OWNER/REPOSITORY): Not
authorized -> [Help 1]
I got the push working using Dockerfile building by passing in the github token as build arg and switching the owner and repo name to their values.

Failed to deploy artifacts: Could not transfer artifact com.foo.bar::jar: from/to central (http://): Broken pipe

While deploying artifact into jfrog, I get the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project : Failed to deploy artifacts: Could not transfer artifact com...::jar:1.0.0-14 from/to central (http://artifactory:8080/artifact-release): Broken pipe (Write failed)
Verify if the id given in settings.xml and (in pom.xml) are same
<distributionManagement>
<snapshotRepository>
<id>**snapshot**</id>
<name></name>
<url></url>
</snapshotRepository>
<repository>
<id>**central**</id>
<name></name>
<url></url>
</repository>
</distributionManagement>
<servers>
<server>
<id>**snapshot**</id>
<username></username>
<password></password>
</server>
<server>
<id>**central**</id>
<username></username>
<password></password>
</server>
</servers>
User mentioned in settings.xml might not having proper access (in artifactory) to deploy artifact
<servers>
<server>
<id></id>
<username>**user**</username>
<password></password>
</server>
<server>
<id></id>
<username>**user**</username>
<password></password>
</server>
</servers>

Maven FTP Deployment: Unable to create directory

For the past couple of hours, I have been unable to solve this issue. Note that I have tried looking for solutions with no avail.
Anyway, my issue is that I am unable to create a directory with the Maven Wagon plugin. Here is an snip of the error for reference.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project spigotsite:
Failed to deploy artifacts: Could not transfer artifact be.maximvdw:spigotsite:jar:0.0.12-20160523.053812-1 from/to public (ftp://***.***.***.***): Unable to create directory be -> [Help 1]
Snip of pom.xml
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>public</id>
<name>Repository</name>
<url>ftp://***.***.***.***</url>
</repository>
</distributionManagement>
Snip of settings.xml
<servers>
<server>
<id>public</id>
<username>***</username>
<password>***</password>
</server>
</servers>
I have verified that I am able to log onto the FTP and create a directory. I gave the FTP user full write permission to the folder as well as tested writing to the folder itself. I seem to be overlooking something and I appreciate if anyone could point out my mistake. Thank you in advance.
It worked for me:
POM.xml
<build>
...
<extensions>
<!-- Enabling the use of FTP -->
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>3.0.0</version>
</extension>
</extensions>
</build>
<distributionManagement>
<repository>
<id>ftp-repository</id>
<url>ftp://...myhost.../srv/ftp/</url> <!-- repository location -->
</repository>
</distributionManagement>
SETTINGS.xml
<servers>
<server>
<id>ftp-repository</id>
<username>myusername</username>
<password>mypassword</password>
<configuration>
<endpointChecking>false</endpointChecking>
</configuration>
</server>
...
</servers>

Why Artifactory Maven and Oracle fail to communicate?

I hope an answer will be a universal guide on how to connect Maven, Oracle And Artifactory and will become most usefull webpage on the net. Most likely this question will be marked down, but I just give up on Maven, Artifactory and Oracle.
I am running windows 7-64 with maven installed as a part of Oracle jdev. Company has Artifactory setted up and running on vpn network.... but somethings are not right.
Following simple instructions on:
http://biemond.blogspot.co.uk/2013/07/maven-support-in-weblogic-jdeveloper.html
fails at first instruction:
Install the oracle maven sync plugin to your local repository
the command:
mvn deploy:deploy-file -DpomFile=oracle-maven-sync.12.1.2.pom -Dfile=oracle-maven-sync.12.1.2.jar
the error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default-cli) on project standalone-pom: The parameters 'url' for goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file are missing or invalid -> [Help 1]
adding
-Durl=file://C:\Users\{user}\.m2
seems to install that artifact to my local .m2 repo
C:\Users\{user}\.m2\com\oracle\maven\oracle-maven-sync\12.1.2-0-0
but only seems, then I get to number 3 on that tutorial:
mvn com.oracle.maven:oracle-maven-sync:help
gives an error:
[ERROR] Error resolving version for plugin 'com.oracle.maven:oracle-maven-sync' from the repositories [local (C:\Users\{user}\.m2), central (http://repo.maven.apache.org/maven2)]: Plugin not found in any plugin repository -> [Help 1]
So the plugin failed to install?
Oracle Maven repository is password protected due to weird oracle thoughts, Artifactory has external Central and Oracle repositories why letting it mirror everything stops maven from even finding deploy module?
here is my settings.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<username>user</username>
<password>xxx</password>
<id>central</id>
</server>
<server>
<username>user</username>
<password>xxx</password>
<id>snapshots</id>
</server>
</servers>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release-local</name>
<url>http://art.host.ru:8081/artifactory/libs-release-local</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot-local</name>
<url>http://art.host.ru:8081/artifactory/libs-snapshot-local</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release-local</name>
<url>http://art.host.ru:8081/artifactory/plugins-release-local</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-snapshot-local</name>
<url>http://art.host.ru:8081/artifactory/plugins-snapshot-local</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
<profile>
<id>oracle-maven</id>
<properties>
<oracle-maven-sync.oracleHome>C:\Oracle\Middleware\Oracle_Home</oracle-maven-sync.oracleHome>
<oracle-maven-sync.testOnly>false</oracle-maven-sync.testOnly>
<oracle-maven-sync.failOnError>false</oracle-maven-sync.failOnError>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>oracle-maven</activeProfile>
</activeProfiles>
</settings>
Well, I think you just follow the wrong guide. All this manual deployment of some random maven plugins is just wrong.
Just follow the simple and detailed instructions in the Artifactory User Guide and you're good to go.
The problem is with the -Dmaven.repo.local
Do not provide the argument.
Use http://jcenter.bintray.com for most of the artifacts
And for Oracle: oracle-maven-sync plugin
oracle instructions
$ORACLE_HOME = where jdev 12.1.2
$M2_HOME = $ORACLE_HOME/oracle_common/modules/org.apache.maven_3.0.4
$M2 = $M2_HOME/bin (add to $PATH)
artifactory->home->maven settings generate settings.xml put it in ~/.m2
create local repo in artifactory"oracle-local-12.1.2"
settings.xml add following code
<profiles>
<profile>
<properties>
<oracle-maven-sync.oracleHome>$ORACLE_HOME</oracle-maven-sync.oracleHome>
<oracle-maven-sync.testOnly>false</oracle-maven-sync.testOnly>
<oracle-maven-sync.failOnError>false</oracle-maven-sync.failOnError>
<oracle-maven-sync.serverId>oracle-local-12.1.2</oracle-maven-sync.serverId></properties>
artifactory -> username(top right corner) -> enter pass -> unlock -> забрать encrypted password(copy)
add aquired pass to settings.xml for all
go to $ORACLE_HOME/oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/12.1.2 (use cmd/terminal)
mvn deploy:deploy-file -DpomFile=oracle-maven-sync-12.1.2.pom -Dfile=oracle-maven-sync-12.1.2.jar
test it: mvn com.oracle.maven:oracle-maven-sync:help
push artifacts oracle 12.1.2 mvn com.oracle.maven:oracle-maven-sync:push
long time wait (~3000 artifacts > 2 hours)
complete set up of repos and in settings.xml

Resources