Unable to deploy Maven artifacts to snapshot/private Cloudbees repository - maven

I'm using an Ant script to deploy artifacts to my snapshot/private repository but I'm getting a Forbidden exception as follow. Looks like that the username and password are correct because if I change them I get a different error (unauthorized). What I'm missing?
[exec] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default-cli) on project standalone-pom:
Failed to deploy artifacts: Could not transfer artifact br.com.simpleconsulting.portal:portal-client:jar:6.1.0-20121007.102101-1 from/to cloudbees-snapshot (https://repository-tmoreira2020.forge.cloudbees.com/snapshot):
Access denied to: https://repository-tmoreira2020.forge.cloudbees.com/snapshot/br/com/simpleconsulting/portal/portal-client/6.1.0-SNAPSHOT/portal-client-6.1.0-20121007.102101-1.jar, ReasonPhrase:Forbidden. -> [Help 1]

2 common causes of an unauthorized error (403) on CloudBees infrastructure are
uploading with valid credentials that don't have authority to the path in question
uploading with valid credentials to a URL path that doesn't exist
I can see that the URL path listed exists and contains new artifacts - did you get things working after you posted this question?

Try passing settings.xml explicitly to your maven commands:
mvn -s ~/.m2/settings.xml deploy
Also, ensure that you have webdav-jackrabbit extension configured in the build section of your maven pom.xml
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav-jackrabbit</artifactId>
<version>2.2</version>
</extension>
</extensions>

Related

Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy Github Packages

I am trying to deploy my artifact as a packaged to Github Packages. On clean deploy I get
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project cardgame: Failed to deploy artifacts: Could not transfer artifact org.moderatelycomfortablechair:cardgame:jar:0.0.1-20201222.145834-1 from/to github (https://maven.pkg.github.com/ModeratelyComfortableChair/CardGame): Access denied to https://maven.pkg.github.com/ModeratelyComfortableChair/CardGame/org/moderatelycomfortablechair/cardgame/0.0.1-SNAPSHOT/cardgame-0.0.1-20201222.145834-1.jar. Error code 403, Forbidden -> [Help 1]
My pom.xml contains the following
<modelVersion>4.0.0</modelVersion>
<groupId>org.moderatelycomfortablechair</groupId>
<artifactId>cardgame</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cardgame</name>
...
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub ModeratelyComfortableChair Apache Maven Packages</name>
<url>https://maven.pkg.github.com/ModeratelyComfortableChair/CardGame</url>
</repository>
My ~/.m2/settings.xml is the same as here, where username and owner is ModeratelyComfortableChair (my github username) and password is a personal access token with repo and read write access.
Firstly you need to have read:write access to packages on your Personal Access Token (PAT). That should solve your problem.
This works very well with your private repositories.
However, for those working with organization repositories and having Single Sign-On (SSO) enforced, this might not be sufficient. The token must be explicitly authorized for SSO. And Maven command doesn't prompt for that.
There are different ways to authrorize the token, two of which are as explained below.
[Easiest] Login to GitHub account and navigate to the PAT section. There you'll find an option to enable SSO for the given token. (Token name could be different in your case)
Try to clone your repository using Git commandline - git clone https://[USERNAME]:[TOKEN]#[GIT_ENTERPRISE_DOMAIN]/[ORGANIZATION]/[REPO].git
It will throw an error and give you a URL for authorizing the token with SSO. Access the URL in a browser and authorize the SSO for the given token. Once authorized, you should be able to publish/deploy your artifacts.
Cheers!

Configure Nexus connection for maven deployment

Im trying to gain some experience in working with Nexus and TeamCity.
To do so i set both servers up on my local machine and configured a pet project thats located on github.com in a private repo.
But i can't get my TC-Build to run because the Maven deploy step fails with following message.
[14:58:55][Step 2/2] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project Worm: Failed to deploy artifacts: Could not transfer artifact org.test.worm:Worm:jar:1.0.0 from/to local_nexus (http://localhost:8081/repository/org.test): Transfer failed for http://localhost:8081/repository/org.test/org/test/worm/Worm/1.0.0/Worm-1.0.0.jar 401 Unauthorized
Seems like it fails due to wrongly configured authorization but i can't find the mistake.
In my projects pom.xml it is configured like this
<distributionManagement>
<repository>
<id>local_nexus</id>
<name>Deployment</name>
<url>http://localhost:8081/repository/org.test</url>
</repository>
</distributionManagement>
and in my mavens settings.xml like this
<server>
<id>local_nexus</id>
<username>admin</username>
<password>admin</password>
</server>
Im using the default admin user (user/pw is correct, logging into nexus with the same user) that is created when installing nexus. Same user that created the repository.
TC running under localhost:8080 and Nexus under localhost:8081
Please tell me what i configured wrongly or what i forgot.
Using mvn help:effective-settings i could confirm that the settings.xml was configured correctly. But it made me realize that my TeamCity Server was using a different (its own) maven instance than my local machine. So the solution was to either set the maven-home for TeamCity or to configure the settings.xml of the other maven instance.
Stupid mistake i should have noticed way sooner.

rtMavenRun() Artifactory plugin not using credentials configured in Jenkins

This is my pipeline:
stage('Deploy') {
environment {
MAVEN_HOME = '/usr/share/maven'
JAVA_HOME= '/usr/local/openjdk-8'
}
steps {
rtMavenResolver (
id: 'resolver-unique-id',
serverId: 'my-server-config',
releaseRepo: 'my-repo',
snapshotRepo: 'my-repo'
)
rtMavenDeployer (
id: 'deployer-unique-id',
serverId: 'my-server-config',
releaseRepo: 'my-repo',
snapshotRepo: 'my-repo'
)
rtMavenRun (
pom: 'pom.xml',
goals: 'help:effective-settings',
//goals: 'deploy',
resolverId: 'resolver-unique-id',
deployerId: 'deployer-unique-id'
)
// This works
rtPublishBuildInfo (
serverId: 'my-server-config'
)
I have the creds and URL configured on jenkins (my-server-config). I know it's configured correctly because rtPublishBuildInfo() works and publishes to Artifactory. The user it's using is a full admin so should be no perms issues.
This is running in a container slave so I had to manually set environment to point to the locations of Maven and Java home for the plugin to find it. It's running the official Maven image
When I try the deploy goal (confirmed working locally with same user creds) I see this error:
[main] WARNING org.codehaus.plexus.PlexusContainer - Could not transfer metadata com.mycompany.app:my-app:1.0-SNAPSHOT/maven-metadata.xml from/to snapshots (https://my-tenant.jfrog.io/my-tenant/my-repo): Not authorized
I tried running the help:effective-settings goal and checked jenkins output. It looks like it's not using my creds? How does this plugin even work with the Jenkins cred binding I set in the config? How does it pass those creds to mvn?
Effective user-specific configuration settings:
<?xml version="1.0" encoding="UTF-8"?>
<!-- ====================================================================== -->
<!-- -->
<!-- Generated by Maven Help Plugin on 2019-10-18T19:04:34Z -->
<!-- See: http://maven.apache.org/plugins/maven-help-plugin/ -->
<!-- -->
<!-- ====================================================================== -->
<!-- ====================================================================== -->
<!-- -->
<!-- Effective Settings for 'root' on 'mypackagepackage-2zbtg-hsxqv' -->
<!-- -->
<!-- ====================================================================== -->
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<localRepository>/root/.m2/repository</localRepository>
<pluginGroups>
<pluginGroup>org.apache.maven.plugins</pluginGroup>
<pluginGroup>org.codehaus.mojo</pluginGroup>
</pluginGroups>
</settings>
Edit 1
Now I think the plugin is totally broken I tried explicitly passing it a global settings file with the right creds and it's still failing:
rtMavenRun (
pom: 'pom.xml',
//global-settings here is a jenkins secret file with the entire contents of a global settings.xml
goals: '--settings ${global-settings} deploy',
resolverId: 'resolver-unique-id',
deployerId: 'deployer-unique-id'
)
I'm seeing this error:
[main] ERROR org.apache.maven.cli.MavenCli - Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project my-app: Execution default-deploy of goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy failed.: NullPointerException -> [Help 1]
Edit 2
OK so even though this works fine locally I tried setting an updated version of the deployment plugin in my pom:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
And now I'm getting another error from the plugin (this still works locally without issue):
Caused by: java.io.IOException: Failed to deploy file. Status code: 409 Response message: Artifactory returned the following errors:
The target deployment path 'com/mycompany/app/my-app/1.0-20191018.195756-35/my-app-1.0-20191018.195756-35.pom' does not match the POM's expected path prefix 'com/mycompany/app/my-app/1.0-SNAPSHOT'. Please verify your POM content for correctness and make sure the source path is a valid Maven repository root path. Status code: 40
Edit 3
Continuing my epic struggle with this crap-ass jfrog plugin I disabled consistency checks on the local repo and it can deploy but now I understand that error. It's transforming my pom and turning 1.0-SNAPSHOT into 1.0-20191018.195756-35 why is it doing that and how to a get it to not mangle my pom file?
Edit 4
I must be a moron or documentation is not very clear (maybe both). I was using the deploy goal because I wanted to deploy. But apparently you don't do that with the plugin- this makes sense to me now. You clean and install the package but leave it to the plugin to deploy it so it puts it in the right location and attaches build info. Using install as a goal works.
Answer is don't use deploy goal. Build the package and the plugin will take care of the deployment part.

Unable to deploy release package to nexus using maven release:perform

I am getting 400 errors when I try to execute maven release: perform.
[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project my-project: Failed to deploy artifacts: Cou
ld not transfer artifact com.acca.project:project:pom:1.0.0-RELEASE from/to acca-nexus (https://nexus.io/repository/project/): Failed to transfer file https://nexus.io/repository/project/myproject/myproject/1.0.0-RELEASE/myproject-1.0.0-RELEASE.pom with status code 400 -> [Help 1]
Following things I have tried
1) I verified, credentials are correct
2) URL for nexus repo is correct
3) I am maintaining the proper 1.0.0-SNAPSHOT name
4) there is no package with the same version in nexus as well
5) Not a network issue as well, I can do maven deploy properly.
Release plugin -config looks like below
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<scmCommentPrefix>[maven-scm] :</scmCommentPrefix>
<goals>deploy</goals>
<releaseProfiles>release</releaseProfiles>
</configuration>
</plugin>
I want to deploy the package when I do maven release: perform, but I am unable to debug beyond this. can someone please tell me how to debug this. Pointing out the issue will also helpful
I fixed the above issue.
The solution was in the nexus repository configuration.
I updated the configuration to "allow redeploy" and it started working.
Thank you

s3-storage-wagon maven plugin and upload to S3 bucket

I need to upload my build artifact to S3 bucket. For this purpose, I'm trying to use s3-storage-wagon maven plugin
This is my configuration in pom.xml:
<distributionManagement>
<repository>
<id>s3.artifacts.release</id>
<url>s3://${artifactrepo.url}/release</url>
</repository>
<snapshotRepository>
<id>s3.artifacts.snapshot</id>
<url>s3://${artifactrepo.url}/snapshot</url>
</snapshotRepository>
</distributionManagement>
<extensions>
<extension>
<groupId>com.gkatzioura.maven.cloud</groupId>
<artifactId>s3-storage-wagon</artifactId>
<version>1.0</version>
</extension>
</extensions>
settings.xml
<server>
<id>s3.artifacts.release</id>
<username>Access key ID</username>
<password>Secret</password>
</server>
<server>
<id>s3.artifacts.snapshot</id>
<username>Access key ID</username>
<password>Secret</password>
</server>
During Maven deploy this plugin fails with the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project pipeline: Failed to retrieve remote metadata com.xxx:xxx:0.0.4-SNAPSHOT/maven-metadata.xml: Could not transfer metadata com.xxx:xxx:0.0.4-SNAPSHOT/maven-metadata.xml from/to s3.artifacts.snapshot (s3://my-backet/snapshot): Could not authenticate: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: 8KJHKHFKHFGA48; S3 Extended Request ID: 2j/bW/INn+qCzVqwer+Fawv75qwerkUPmO7flQa8z34523445werrtwertGTs919tJpYoM=) -> [Help 1]
We are using GUI S3 client for Windows and are able to access the target S3 bucket without any issue. What may be wrong with our s3-storage-wagon maven plugin configuration?
Looks like your AWS credentials for S3 do not have upload (PutObject most likely) permission. The portion of the message telling you this is:
Could not authenticate: Access Denied (Service: Amazon S3;...
Or perhaps you need to setup your ~/.aws/credentials file so that the default profile is able to access the S3 bucket you are using.
If you need to use alternate profiles (the non-default profile in your ~/.aws/credentials file) you will likely need to specify the profile using one of the many ways AWS SDKs support this. I would start by trying AWS_PROFILE=my-profile such as the following (assuming bash):
AWS_PROFILE=my-profile mvn deploy
See https://github.com/gkatzioura/CloudStorageMaven/tree/master/S3StorageWagon#authentication for further info on how to provide credentials to this plugin.

Resources