rtMavenRun() Artifactory plugin not using credentials configured in Jenkins - maven

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.

Related

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

Issue in adding third party dependency in Maven during Jenkins build - ODM

I am trying to build ODM projects outside of eclipse using the Jenkins pipeline and Maven plugin. I am following the link : https://www.ibm.com/support/knowledgecenter/en/SSQP76_8.9.0/com.ibm.odm.dserver.rules.designer.run/build_topics/con_buildcmd_intro.html
Though this link works well without the Jenkins pipeline in my local(Windows), but when I try to run the same setup in Jenkins(Linux machine), I am getting the following error :
[WARNING] The POM for com.ibm.rules.buildcommand:rules-compiler-maven-plugin:jar:8.10.0.0 is missing, no dependency information available
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. # helloWorld:hello-xom:[unknown-version], /var/lib/jenkins/workspace/odm-devops-build/Hello XOM/pom.xml, line 19, column 21
[ERROR] Unresolveable build extension: Plugin com.ibm.rules.buildcommand:rules-compiler-maven-plugin:8.10.0.0 or one of its dependencies could not be resolved: Failure to find com.ibm.rules.buildcommand:rules-compiler-maven-plugin:jar:8.10.0.0 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 #
[ERROR] Unknown packaging: decisionservice # helloWorld:hello-main:[unknown-version], /var/lib/jenkins/workspace/odm-devops-build/Hello Main Service/pom.xml, line 14, column 16
The pom file which is referred in the above error is as below:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>helloWorld</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
<relativePath>..</relativePath>
</parent>
<artifactId>hello-main</artifactId>
<packaging>decisionservice</packaging>
<build>
<plugins>
<plugin>
<groupId>com.ibm.rules.buildcommand</groupId>
<artifactId>rules-compiler-maven-plugin</artifactId>
<configuration>
<deployments>
<deployment>
<name>simple dep</name>
</deployment>
</deployments>
<resolvers>
<resolver>
<!-- The values of the kind and url of the project correspond to the 'kind' and 'url' attribute values of an 'entries' element in the .ruleproject file. -->
<kind>JAVA_PROJECT</kind>
<url>platform:/Hello XOM</url>
<!-- The artifactKey references the groupId and artifactId of a Maven dependency. -->
<artifactKey>${project.groupId}:hello-xom</artifactKey>
</resolver>
</resolvers>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hello-xom</artifactId>
<type>jar</type>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Please let me know if anyone has faced a similar issue or has a possible resolution to the above issue.
Thanks in advance.
Possible resolution: "install the Build Command Maven plugin and its related Operational Decision Manager artifacts in your Maven repository" ... "on each machine that contains build agents"
To deploy the Build Command Maven plugin to a remote Maven repository, you must configure Maven in your environment. You then use the following command: mvn deploy:deploy-file -Dfile=rules-compiler-maven-plugin.jar -DpomFile=rules-compiler-maven-plugin.pom
This requires access to the Jenkins / Maven server, and at many companies would be done by DevOps.
You install the Build Command Maven plugin and its related Operational Decision Manager artifacts in your Maven repository.
Deploying the Build Command plugin
You deploy the plugin only once on each machine that contains build agents.
To deploy the Build Command Maven plugin to a remote Maven repository, you must first configure Maven in your environment.
Then, in <InstallDir>/buildcommand/rules-compiler, open a command prompt.
Use the following command:
mvn deploy:deploy-file -Dfile=rules-compiler.jar -DpomFile=rules-compiler-maven-plugin.pom
If you do not have a remote repository, you can test the plugin locally. You run the following command:
mvn install:install-file -Dfile=rules-compiler.jar -DpomFile=rules-compiler-maven-plugin.pom
This command adds the following plugin in your local Maven repository:
com/ibm/rules/buildcommand/rules-compiler
 Deploying the annotations archive
If you want to build COBOL projects or projects that use XOM annotations, you must also deploy the annotations archive to your environment before you can build the projects.
In <InstallDir>/buildcommand/rules-compiler, open a command prompt.
Use the following command:
mvn deploy:deploy-file -Dfile=rules-compiler.jar -DpomFile=xom-annotations.pom
If you do not have a remote repository, you can test the plugin locally. You run the following command:
mvn install:install-file -Dfile=rules-compiler.jar -DpomFile=xom-annotations.pom
This command adds the following plugin in your local Maven repository:
com/ibm/rules/buildcommand/xom-annotation
Source

sonar.host.url not working with sonar-maven-plugin:2.7

After upgrading my POMs to sonar-maven-plugin:2.7 the configuration does not work any more. My configuration in settings.xml is like this:
<profile>
<id>sonar</id>
<properties>
<sonar.jdbc.url>jdbc:postgresql://my.server:5432/sonar</sonar.jdbc.url>
<sonar.jdbc.driverClassName>org.postgresql.Driver</sonar.jdbc.driverClassName>
<sonar.jdbc.username>xxxxx</sonar.jdbc.username>
<sonar.jdbc.password>yyyyy</sonar.jdbc.password>
<sonar.host.url>http://my.server</sonar.host.url>
</properties>
</profile>
The build is started with -Psonar of course. With version 2.6 everything is fine, with 2.7 I get
[INFO] --- sonar-maven-plugin:2.7:sonar (default-cli) # myproject ---
[INFO] User cache: C:\Users\me\.sonar\cache
[ERROR] SonarQube server 'http://localhost:9000' can not be reached
...
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.7:sonar (default-cli) on project myproject: Fail to download libraries from server: java.net.ConnectException: Connection refused: connect -> [Help 1]
Starting the build with -X gives me the correct mojo configuration in both cases, especially the url is still correct in the log
[DEBUG] (f) sonarHostURL = http://my.server
Even deleting the mentioned caching directory does not help.
What can I do except of managing the plugin to version 2.6?
We are investigating the issue. Ticket was created: https://jira.sonarsource.com/browse/MSONAR-129
In the meantime you could either lock the SQ plugin to version 2.6 or pass all properties using command line.
Workaround: Adding -Dsonar.host.url=http://my.server:9000 to mvn command works for me
Better than disabling the plugin, you may fix the plugin version to 2.6, which works fine, taking into account sonar.host.url.
For instance, with Maven in my case:
<pluginManagement>
</plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.6</version>
<!-- sonar.host.url not working with version 2.7 -->
</plugin>
</plugins>
</pluginManagement>
I use the full qualified goal in the CI server to run the sonar goals:
mvn org.codehaus.mojo:sonar-maven-plugin:2.6:sonar
Since we use the templates in TeamCity this is not so much of a disaster. Still we were a bit surprised by the event.
Both
mvn -Dsonar.host.url=http://localhost:9000 org.codehaus.mojo:sonar-maven-plugin:2.6:sonar
and
mvn -Dsonar.host.url=http://localhost:9000 org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar
worked for me :
Instead of reconfiguring all jobs I disabled sonar for all jobs until this gets fixed. I added
<sonar.skip>true</sonar.skip>
to the sonar profile in settings.xml.

How to release and reference Grails plugins using local Maven repository

Summary
I create two plugins A and B with Grails 2.3.4 where B is a plugin used by A plugin. I get error when I use A plugin in my application.
Details
When I run the following command, for plugin B, it successfully release the plugin to local maven repository. I can see it in the ~/.m2/... folder.
~plugin-b: grails maven-install
Then I add a reference to plugin B with plugin A, so I add the reference to BuildConfig in plugin A:
plugins {
compile "com.test.plugins:b:1.0.0-SNAPSHOT"
}
Now, I think, I should be able to run the next command and the plugin should be released to the local maven repository but I get the error instead:
~plugin-a: grails maven-install
| Plugin packaged grails-a-1.0.0-SNAPSHOT.zip
| Generating POM file.....
| Error Could not find artifact com.test.plugins:b:jar:1.0.0-SNAPSHOT (scope: compile) (Use --stacktrace to see the full trace)
| POM generated: //dependencies/dependencies_A_plugin/target/pom.xml...
Maven install complete.
Here is the generated POM file:
// pom header
<artifactId>a</artifactId>
<packaging>zip</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>A</name>
<description>Brief summary/description of the plugin.
</description>
<url>http://grails.org/plugin/a</url>
<developers>
<developer>
<name>Your name</name>
</developer>
</developers>
<dependencies>
<dependency>
<groupId>com.test.plugins</groupId>
<artifactId>b</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
... just ending tags
Actually, also plugin A has been released to the local Maven repository, but it is probably corrupted, because when I create a Grails application and add a reference to A plugin into BuildConfig, then I am not even able to start up that application.
~ grails
| Error Resolve error obtaining dependencies: Could not find artifact com.test.plugins:b:jar:1.0.0-SNAPSHOT (Use --stacktrace to see the full trace)
| Error Could not find artifact com.test.plugins:b:jar:1.0.0-SNAPSHOT
So, the application has found A plugin, but not the B plugin, which is referenced by A plugin. To me, it seems there is an issue with generated POM file in the local Maven repository for the A plugin. There is probably missing:
<type>zip</type>
But I have not found a way how to add the type to that dependency.
Anyone able to help?

Unable to deploy Maven artifacts to snapshot/private Cloudbees repository

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>

Resources