1
votes

I'm trying to set up a jenkins pipeline for publishing a zip file to jfrog artifactory.

I am using com.jfrog.artifactory plugin to do so. This works great from command line gradle and I can run the artifactoryPublish task to publish the artifacts and tie them back to the module, which then has a tie back to the artifacts.

The artifacts show up with the properties:

build.name = `projectname` 
build.number = `some large number`

And I can click from them to the build/module and back to the artifact.

However, when I run this from a jenkinsfile pipeline, the artifacts get published and get tied back to the module, but then the module does not successfully tie the module back to the artifacts.

The artifacts do not receives the build.name and build.number properties and i cannot click from the module back to the artifacts, as the module cannot find or resolve the paths back to the artifacts(a zip file and a generated pom).

I am passing the params from jenkins like: ORG_GRADLE_PROJECT_buildInfo.build.number=${env.BUILD_NUMBER} which seems to work on other projects... but for whatever reason I cannot shake it.

I can include more jenkinsfile if that would help debug, but i'm really just checking out a repository and trying to publish it.

I have been reading heavily the documentation here:

https://www.jfrog.com/confluence/display/RTF/Gradle+Artifactory+Plugin

and haven't been able to make it work through -Pproject stuff.

Does anyone have any idea what else I can try? i don't really want to use the jenkins pipeline artifactory plugin directly because it's so nice to be able to deploy from the command line too.

build.gradle:

publishing {
    publications {

        ManualUpdaterPackage(MavenPublication){
            artifact assembleManualUpdaterPackage
        }
    }
}

artifactory {
    contextUrl = "${artifactoryUrl}"   //The base Artifactory URL if not overridden by the publisher/resolver
    publish {
        defaults {
            publications('ManualUpdaterPackage')
        }
        repository {
            repoKey = project.version.endsWith('-SNAPSHOT') ? snapshotRepo : releaseRepo
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true
        }

    }
}
task assembleManualUpdaterPackage (type: Zip){
    dependsOn anotherTask
    from (packageDir + "/")
    include '**'
//    archiveName "manualUpdaterPackage-${version}.zip"
    destinationDir(file(manualUpdaterZipDir))
}

jenkinsfile snip:

withCredentials(
        [
                [
                        $class          : 'UsernamePasswordMultiBinding',
                        credentialsId   : 'validcreds',
                        passwordVariable: 'ORG_GRADLE_PROJECT_artifactory_password',
                        usernameVariable: 'ORG_GRADLE_PROJECT_artifactory_user'
                ]
        ]
) {
    withEnv(
            [                      
                    "ORG_GRADLE_PROJECT_buildInfo.build.number=${env.BUILD_NUMBER}",
                    "ORG_GRADLE_PROJECT_buildInfo.build.name=${artifactName}",
                    "ORG_GRADLE_PROJECT_buildInfo.build.url=${env.JOB_URL}"
            ]
    ) {
        sh 'chmod +x gradlew'
        sh "./gradlew --no-daemon clean artifactoryPublish"
    }

}
1

1 Answers

1
votes

https://www.jfrog.com/confluence/display/RTF/Working+With+Pipeline+Jobs+in+Jenkins#WorkingWithPipelineJobsinJenkins-GradleBuildswithArtifactory

Eventually my coworker recommended looking into the Artifactory Pipeline Gradle plugin instead. It is very nice to work with and we've had much quicker success with it.