Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-59108

Artifactory plugin can't publish build info for Gradle builds

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Critical Critical
    • None
    • Linux
      Jenkins v2.189
      Artifactory Plugin v3.3.2
      Gradle Plugin v1.33
      Pipeline Plugin v2.6

      We have been using the Gradle and Artifactory plugins on our production Jenkins instance for years using the traditional freestyle job types. We are now working on migrating all of our production builds to use Jenkins Pipeline scripts. As part of that transition we have a need to build Java projects using Gradle and publish artifacts generated by these projects to Artifactory. Further, nearly all of our production builds are performed within dockerized build environments so all build time dependencies can be managed and reproduced. However, I can not for the life of me find a way to get a simple Gradle operation to publish artifacts along with the requisite build info and back-links to the Artifactory build information. Here is an brief example of the sort of build configuration we are looking to use (in scripted pipeline format):

       

      node {
        stage ("build") {
          // checkout project sources
          checkout scm
      
          // get artifactory connection parameters
          def artifactory_server = Artifactory.server 'server-id'
      
          // construct a gradle build object
          def gradle_proxy = Artifactory.newGradleBuild()
      
          // configure the gradle build environment to use the gradle wrapper
          gradle_proxy.deployer repo: "snapshot-repo", server: artifactory_server
          gradle_proxy.useWrapper = true  // <---- this option appears to be undocumented but I found it when I went looking through the source for the plugin
      
          // build docker build environment from the source repo
          container = docker.build("./docker")
      
          // launch the build environment
          container.inside() {
            // try to build the gradle project...
            // this operation fails
            build_info = gradle_proxy.run rootDir: "master", buildFile: "build.gradle", tasks: ":subproj:artifactoryPublish"
      
            // publish build info if/when the build succeeds
            artifactory_server.publishBuildInfo buildInfo
          }
        }
      } 

       

       

      When running this build, the call to the gradle_proxy.run task produces the following error:

      expected to call org.jfrog.hudson.pipeline.common.types.packageManagerBuilds.GradleBuild.run but wound up catching ArtifactoryGradleBuild; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/ 

      I will say that I am sort of flying blind here. Most of the docs and examples I've found online that integrate Gradle, Jenkins and Artifactory assume that you are using a freestyle job configuration or that you are using a Gradle binary (ie: not the Gradle wrapper) which is deployed explicitly by Jenkins, which is not something we can/want to do in our case. Also, I am not sure if Docker is somehow playing a part in this problem because none of the examples I've found online to orchestrate this type of build use Docker. So maybe this behavior / result is unique to this specific combination of build tools.

      If anyone can tell me whether or not I've missed something obvious here in my build script, or perhaps point me to some documentation or examples that shows how to orchestrate this type of build, I would really appreciate it.

            yahaviz Yahav Itzhak
            leedega Kevin Phillips
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: