简体   繁体   中英

User is not permitted to deploy '.json' into Artifactory Using Gradle

I am trying to deploy a project jar into JFrog Artifactory using gradle. The build.gradle file looks like this (the part necessary for deploy):

buildscript {
 repositories {
    jcenter()
}
dependencies {
    classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.16.1"
}
 configurations.classpath {
    resolutionStrategy {
        cacheDynamicVersionsFor 0, 'seconds'
        cacheChangingModulesFor 0, 'seconds'
    }
 }
}

plugins {
  id 'java'
  id 'com.jfrog.artifactory' version '4.16.1'
  id 'maven-publish'
}


repositories {
   mavenCentral()
   mavenLocal()
   repositories {
     mavenCentral()
     maven {
        url "<artifactoryPath>/artifactory/gcc-maven/"
        credentials {
            username = "${artifactory_user}"
            password = "${artifactory_password}"
        }
    }
}

publishing {
  publications {
    mavenJava(MavenPublication) {
        groupId group
        version version
        from components.java
    }
  }
}

artifactory {
  contextUrl = "${artifactory_contextUrl}"
  publish {
    repository {
        repoKey = 'gcc-maven-local'
        username = "${artifactory_user}"
        password = "${artifactory_password}"
        maven = true
    }
  defaults {
        publications('mavenJava')
        publishArtifacts = true
        properties = ['version': version, 'dev.team': '<project>']
        publishPom = true
  }
}
  resolve {
    repository {
        repoKey = 'gcc-maven'
        username = "${artifactory_user}"
        password = "${artifactory_password}"
        maven = true
    }
  }
}

When I use my username and password everything works fine but when I use a token the .jar .module and .pom files are pushed but not the build descriptor. I have the next error:

> Task :artifactoryDeploy
Deploying build descriptor to: <artifactoryPath>/artifactory/api/build
Could not build the build-info object.
java.io.IOException: Failed to send build descriptor. 403 Response message: {
  "errors" : [ {
    "status" : 403,
    "message" : "User token:fim-artifactory-gcc-maven-rw-token is not permitted to deploy '<name>.json' into '<name>.json'."
  } ]
}

The token looks like this:

{

  "scope" : "member-of-groups:fim-artifactory-gcc-maven api:*",

  "access_token" : "<very_long_string>",

  "expires_in" : 0,

  "token_type" : "Bearer"

}

Some sites suggest that is a checkbox Any Build that must be checked but I don't find it and I think it might be a problem with build.gradle file.

What am I doing wrong? It's there any possibility to skip the build descriptor at all?

I found out in artifactory gradle documentation that build descriptor can be ignored by setting publishBuildInfo to false in the defaults section. In my case it was what I was looking for.

I was also getting the same issue on Jfrog and setting publishBuildInfo = false solved the issue

artifactory {
    contextUrl = "${artifactory_contextUrl}"
    publish {
        repository {
            repoKey = 'libs-local'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true

        }
        defaults {
            publishBuildInfo = false
            publications ('mavenJava')
        }
    }
}

As an alternative to skipping publishing of build info, see the screenshots on this GitHub issue for reference on enabling the required permissions:

https://github.com/jfrog/jenkins-artifactory-plugin/issues/120

“任何构建”复选框 Artifactory 权限页面

“构建操作”“部署”复选框 Artifactory

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