Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publish to Artifactory from Bamboo 6

I am using Bamboo 6.0.3 build 60004 and I installed the version 2.1.0 of the official Artifactory plugin for Bamboo.

The build.gradle of the project looks like:

apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'
...
task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
    classifier = 'javadoc'
    from androidJavadocs.destinationDir
}

task androidSourcesJar(type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.srcDirs
}

artifacts {
    archives androidSourcesJar
    archives androidJavadocsJar
}

afterEvaluate {
    androidJavadocs.classpath += files(android.libraryVariants.collect { variant ->
        variant.javaCompile.classpath.files
    })
}

publishing {
    publications {
        android.buildTypes.all { variant ->
            "${variant.name}Aar"(MavenPublication) {
                // set values from Android manifest file
                groupId group
                version version
                if (variant.name == "release") {
                    artifactId project.getName()
                }
                else {
                    artifactId "${project.getName()}-${variant.name}"
                }

                artifact "$buildDir/outputs/aar/${project.getName()}-${variant.name}-${version}.aar"
                artifact androidJavadocsJar

                pom.withXml {
                    def dependenciesNode = asNode().appendNode('dependencies')

                    // List all compile dependencies and write to POM
                    configurations.compile.getAllDependencies().each { Dependency dep ->
                        if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified")
                            return // ignore invalid dependencies

                        def dependencyNode = dependenciesNode.appendNode('dependency')
                        dependencyNode.appendNode('groupId', dep.group)
                        dependencyNode.appendNode('artifactId', dep.name)
                        dependencyNode.appendNode('version', dep.version)

                        if (!dep.transitive) {
                            // If this dependency is transitive, we should force exclude all its dependencies them from the POM
                            def exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
                            exclusionNode.appendNode('groupId', '*')
                            exclusionNode.appendNode('artifactId', '*')
                        } else if (!dep.properties.excludeRules.empty) {
                            // Otherwise add specified exclude rules
                            def exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
                            dep.properties.excludeRules.each { ExcludeRule rule ->
                                exclusionNode.appendNode('groupId', rule.group ?: '*')
                                exclusionNode.appendNode('artifactId', rule.module ?: '*')
                            }
                        }
                    }
                }
            }
        }
    }
}

def libraryGroupId = group
def libraryVersion = version

artifactory {
    contextUrl = '<artifactory_url>'

    publish {
        repository {
            repoKey = '<repoKey>'

            username = artifactory_username
            password = artifactory_password
        }
        defaults {
            android.buildTypes.all { variant ->
                publications("${variant.name}Aar")
                publishArtifacts = true
            }

            properties = ['qa.level': 'basic', 'dev.team': 'core']
            publishPom = true
        }
    }
}

When I run the command gradle build assembleRelease artifactoryPublish on my laptop, it uploads in the Artifactory repo an aar and a pom file.

I tried using the Artifactory Deployment task in the deployment project that runs after a build task that does gradle build assembleRelease (so the same but without the publishing to artifactory), but it instead publishes only the aar file and the directory structure in artifactory doesn't look the same (it does not breakdown the package name by subfolder). How to achieve the same with Bamboo?

like image 638
Guillaume Avatar asked Jun 16 '17 06:06

Guillaume


People also ask

How do you deploy artifacts to Artifactory?

To deploy build artifacts through Artifactory you must add a deployment element with the URL of a target local repository to which you want to deploy your artifacts. To make this easier, Artifactory displays a code snippet that you can use as your deployment element.

How do I publish a jar to JFrog?

The easiest way, and the least DevOps-friendly way, to upload a JAR to an Artifactory repository is to simply log in to the administrative console, select a target folder and drag and drop the JAR onto the deployment screen. It's not a process that lends itself to CI and automated deployment, but it works.

How do I upload artifacts to JFrog Artifactory using Jenkins?

Overview. To install the Jenkins Artifactory Plugin, go to Manage Jenkins > Manage Plugins, click on the Available tab and search for Artifactory. Select the Artifactory plugin and click Download Now and Install After Restart.


2 Answers

Don't use JFrog, we use Nexus, but it looks like that Deployment Project task in the plugin is designed just to take the shared/published artifacts from the build plan the Deployment Project is dependent on and upload those to Artifactory. So for your first problem, the POM not being uploaded, is the POM a shared artifact in the source build plan feeding the Deployment Project? So you have two shared artifacts in that build plan, the archive AAR file and the POM?

For your second problem, it may depend on how you define the path to shared artifact in source build plan. It doesn't look like the deployment task gives you any options about where to write the artifact to in artifactory. However, I notice the normal build plan task uses a JSON file descriptor where you have more control:

https://www.jfrog.com/confluence/display/RTF/Using+File+Specs

So I wonder if you would have more flexibility if you published your artifact from the feeding normal Build Plan rather than from the Deployment Project, and just downloaded the artifact from artifactory at the beginning of your Deployment Project tasks for that environment.

Not a solution really - just a bunch of things to look at that might help.

like image 121
Jim Weaver Avatar answered Sep 27 '22 19:09

Jim Weaver


Looks like there is an update available for versions 6+ for Bamboo Server located here: https://marketplace.atlassian.com/plugins/org.jfrog.bamboo.bamboo-artifactory-plugin/server/overview

However, I am trying it now with Atlassian Bamboo version 6.3.2 build 60307 and keep getting this error:

  Could not execute task  no Plugin with key 'org.jfrog.bamboo.bamboo-
   artifactory-plugin:artifactoryGenericResolveTask' is installed.

Tried adding it as an executable as documented here https://www.jfrog.com/confluence/display/RTF/Bamboo%20Artifactory%20Plug-in

But still receiving the error. So trying again using the spec file it recommends just using generic resolve task but still no luck.

like image 33
isaac weathers Avatar answered Sep 27 '22 18:09

isaac weathers