-
Bug
-
Resolution: Unresolved
-
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.
- is caused by
-
JENKINS-58643 CPS Mismatches on cpsScript.InvokeMethod
- Resolved
I probably should mention that I have successfully managed to get parts of the jenkins-gradle-artifactory integration to work in isolation from one another. For example, if I create a spec file that lists all the artifacts produced by the Gradle build and pass that to the Artifactory server instance in the Jenkins build script, I can publish the artifacts and build information is correctly attached to the files, and hyperlinks to the buildinfo records are added to the Jenkins build pages. However this solution forces me to duplicate the list of artifacts - once in the build.gradle file and again in the file spec in the Jenkinsfile. So sooner or later one of these is bound to get out of sync and break.
Similarly, if I don't use any of the Jenkins Artifactory plugin logic directly, but merely call `./master/gradlew artifactoryPublish`, Gradle will successfully publish files to Artifactory. However, the Jenkins build info is not attached to the published artifacts and the hyperlinks in the Jenkins build pages are not added, so this is not a workable solution either.