Chanafot
Chanafot

Reputation: 796

Jenkins Gradle build with wrapper, using artifactory plugin

Is there a way to do this?. Want to publish gradle .jar in Artifactory. I was able to do a maven build with installed maven version in jenkins an publishing successfully the war in artifactory, but now devs want to move to gradle build using gradle wrapper instead of maven. Normal Gradle build works just fine using this code.

stage('Clean Build') { 
        
                
        withGradle { // using gradle wrapper
            
            
            sh './gradlew clean build'
      }
}

But when I try to implement this with Artifactory plugin I can´t. I´m getting.

    [Pipeline] ArtifactoryGradleBuild
[api-build] $ /var/lib/jenkins/workspace/api-build/gradlew --init-script /var/lib/jenkins/workspace/api-build@tmp/artifactory/init-artifactory11329321758849387716gradle clean artifactoryPublish -b ./build.gradle
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.

* What went wrong:
Failed to create Jar file /var/lib/jenkins/.gradle/caches/jars-8/8535adf040d7c5fdb7fd6bc28bb0ef3f/ok.
> Prefix string "ok" too short: length must be at least 3

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 8s

this is the pipeline code:

node {
    def server  = Artifactory.server 'artifactory'
    def rtGradle = Artifactory.newGradleBuild()
    def buildInfo
    


    jdk = tool name: 'JDK11'
    //jdk = tool name: 'Java 8'
    env.JAVA_HOME = "${jdk}"
    
     stage('Get Code from Bitbucket') { 
        
                git branch: "${branch}", 
                credentialsId: 'jenkins',
                url: 'ssh://[email protected]/project1/api1'
                
        sh "chmod 755 gradlew"      
    }
    
    stage('Artifactory Configuration') {
       
        // Set Artifactory repositories for dependencies resolution and artifacts deployment.
        rtGradle.deployer server: server, repo: 'myrepo'
        rtGradle.useWrapper = true
        
                
    }

     stage('Gradle build') {

     withGradle {   

       
 buildInfo = rtGradle.run rootDir: ".", buildFile: 'build.gradle', tasks: 'clean artifactoryPublish'

     }
    
    }


stage('Publish build info') {
       
       server.publishBuildInfo buildInfo
    }
    

}

Was anybody able to make this work? thank you in advance.

Upvotes: 0

Views: 1732

Answers (1)

Or-G
Or-G

Reputation: 136

This issue is duplicates of this and there is also a PR fix for that which describes the root cause of the bug. As a temporary workaround, use Gradle V6.5.1 or below.

Upvotes: 6

Related Questions