Jenkins, Gradle, Artifactory and SNAPSHOTs vs. RELEASEs


(Daniel Sandberg) #1

Hi.

We are having difficulty figuring out how to get Jenkins to work with Gradle when it comes to resolving and publishing artifacts in Jenkins.

We have the standard Artifactory OSS (no promotions, properties, etc) installation with libs-snapshot-local and libs-release-local, i.e. the “Maven way”. When using the “Gradle-Artifactory Integration” in Jenkins one can only enter a single publication repo and a single resolution repo - there is no concept of releases and snapshots.

We do need to separate these things since the release-repo is automatically rsync’d to production file servers for later deployment. On top of this we also have plugin resolution and publishing which are things used for building and not for deployment to production machines.

How do we make this work?

We are using the maven-publish plugin in our build-scripts and have ended up with a shared init.gradle (for the common stuff) so we can at-least build and publish from our local machines. Apparently the Jenkins-plugin generates an init-script that configures the artifactory gradle-plugin so the only option we see right now is to add our init.gradle to Jenkins (in place of the Jenkins plugin) and maybe(?) change it to use the artifactory plugin for publications. Even though we probably can solve the resolution issue by adding a virtual repo to the Artifactory we still face the issue of how to get the credentials in place without having them shown in plain text.

Our preferred solution would be to stop using snapshots and use some kind of repo-promotion/properties scheme, but that won’t happen any time soon since Artifactory Pro costs $3000 per server and there are other process issues to resolve first.

current init.gradle

allprojects {
    /* Default company group */
    group = 'com.example'

    /* Resolving dependencies */
    repositories {
        mavenLocal()
        maven {
            name "releases"
            url = "${artifactory_contexturl}libs-release"
            credentials {
                username = "${artifactory_user}"
                password = "${artifactory_password}"
            }
        }
        maven {
            name "snapshots"
            url "${artifactory_contexturl}libs-snapshot"
            credentials {
                username = "${artifactory_user}"
                password = "${artifactory_password}"
            }
        }
    }

    /* Publishing */
    apply plugin: 'maven-publish'
    publishing {    
        repositories {
            maven {
                url  "${artifactory_contexturl}"+ (version.contains('SNAPSHOT') ? 'libs-snapshot-local' : 'libs-release-local')
                credentials {
                    username "${artifactory_deployer}"
                    password "${artifactory_deployer_password}"
                }
            }
        }
    }

}

Preferred way to publish snapshots/releases to Artifactory?
(Christoph Nenning) #2

In our company we have several jenkins-build-jobs for each project. SNAPSHOTs are pushed to artifactory by CI-Builds while RELEASEs are pushed by Stable-Builds. A big difference between them is that CI-Builds are building git master and are run automatically while Stable-Builds are building tags and are triggered manually.

Beside that we don’t configure aritfactory uploads in gradle (as seen in your sample code) but configure it in jenkins. IMO that makes it easier to handle credentials.