简体   繁体   中英

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 its configured correctly because rtPublishBuildInfo() works and publishes to artifactory. The user its 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. Its running the official mavenn 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 its 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: now i think the plugin is totally broken I tried explicitly passing it a global settings file with the right creds and its 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'
)

Im 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 EDIT: 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 Im 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 EDIT EDIT: 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. Its 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 EDIT EDIT EDIT: 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 dont 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 dont use deploy goal. build the package and the plugin will take care of the deployment part

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM