如何使用Jenkins Artifactory插件从Jenkins管道向Artifactory发布Android应用程序的多个构建变体?

时间:2017-02-08 21:52:13

标签: android jenkins gradle artifactory

我有一个Android应用程序有四个构建变体(devDebug,devRelease,tstDebug,tstRelease)。我通过Jenkins Pipeline构建它们,并希望将它们上传到我们公司的Artifactory服务器。 创建了所有四个apk文件,但只有其中一个上传。上传的是devDebug,但我猜选择的那个只是因为一些巧合。 当我构建一个非常相似的Android 时,所有四个aar文件都会上传并按预期设置其分类器。 为了上传所有变种,我设置了android.publishNonDefault = true

我注意到在我的应用程序项目'archives'配置包含com.android.build.gradle.internal.publishing.ApkPublishArtifact实例的情况下,而在我的库的情况下有org.gradle.api.internal。 artifacts.publish.ArchivePublishArtifact_Decorated实例。这可能是Artifactory插件的问题,但这只是一个微弱的猜测。

我的问题是: 如何从单个构建中上传所有四个apks并通过修复构建配置或将它们转换为适当的集合来正确设置其分类器? 如果可能,我需要一个通用的解决方案,因为我们有几个Android应用程序以相同的方式部署 我也对为什么apk文件与aars的收集方式不同感兴趣?

请注意,我正在使用Jenkins Artifactory Plugin(不是Gradle Artifactory Plugin),我正在使用Jenkins Pipeline(不是旧的Freestyle工作),我需要使用这些组件的解决方案。 我是Gradle和Android的新手(我甚至不是Android开发人员,而是发布经理),但我对Pipeline和Artifactory很满意。

我在这一点上非常困难,非常感谢任何帮助。谢谢!

详情。

版本:

Artifactory Professional 4.8.2 rev 40222
Jenkins ver. 2.40
Artifactory Plugin 2.9.1

com.android.tools.build:gradle:2.0.0
compileSdkVersion 25
buildToolsVersion "25.0.1"

$ ./gradlew -version

------------------------------------------------------------
Gradle 2.10
------------------------------------------------------------

Build time:   2015-12-21 21:15:04 UTC
Build number: none
Revision:     276bdcded730f53aa8c11b479986aafa58e124a6

Groovy:       2.4.4
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.8.0_31 (Oracle Corporation 25.31-b07)
OS:           Windows 8.1 6.3 amd64

的build.gradle:

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0'
    }
}


// Plugins
apply plugin: 'com.android.application'


allprojects {
    group = "eu.dorsum.cm.dummy.android.single"
    version = "1.0.0-SNAPSHOT"
}

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.1"
    publishNonDefault true

    defaultConfig {
        applicationId project.group
        minSdkVersion 17
        targetSdkVersion 25
        versionCode 1
        versionName project.version
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
        dev {
            // configuration to access DEV backend comes here
        }
        tst {
            // configuration to access TST backend comes here
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:25.0.1'
}

build.doLast {
  println "----------------------------------------------------------------"
  configurations.each { configuration ->
    println configuration
    configuration.allArtifacts.each { arti ->
      println "  a=$arti (${arti.class})"
    }
  }
}

init.gradle:

allprojects {
    buildscript {
        repositories {
            maven {
                url "${System.properties['artifactory.url']}/mvn-libs-all"
                credentials {
                    username = "${System.properties['artifactory.user']}"
                    password = "${System.properties['artifactory.password']}"
                }
            }
        }
    }

    rootProject.buildscript.repositories.each {
        repositories.add(it)
    }
}

管道脚本:

node {
    stage("Checkout") {
        echo "GRADLE_USER_HOME: ${env.GRADLE_USER_HOME}"
        checkout poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'WipeWorkspace']], submoduleCfg: [], userRemoteConfigs: [[url: 'file:///c:/workspace/stash-dev/cmdum/dummy-android-single-apk']]]
    }

    stage("Build") {
        def server = Artifactory.server 'artifactory-loc'
        def rtGradle = Artifactory.newGradleBuild()
        rtGradle.resolver server: server, repo: 'mvn-libs-all'
        rtGradle.deployer server: server, repo: 'mvn-local'
        rtGradle.useWrapper = true
        rtGradle.usesPlugin = false

        withEnv(["JAVA_HOME=${tool 'JDK 1.8'}", "GRADLE_USER_HOME=C:/Users/lkp/.gradle"]) {
            def buildInfo = Artifactory.newBuildInfo()
            buildInfo.env.capture = true
            buildInfo = rtGradle.run buildFile: 'build.gradle', tasks: 'clean build artifactoryPublish -x lint', buildInfo: buildInfo, switches: "--debug -Dgradle.user.home=${env.GRADLE_USER_HOME}".toString()
            server.publishBuildInfo buildInfo
        }
    }
}

结果:

对于应用程序项目

部署到Artifactory服务器的工件

enter image description here

Artifactory

生成的部署apk的Dependeny信息
<dependency>
    <groupId>eu.dorsum.cm.dummy.android.single</groupId>
    <artifactId>dummy-android-single-apk</artifactId>
    <version>1.0.0-20170208.200909-1</version>
    <type>apk</type>
</dependency>

内置二进制文件

$ ls -1 build/outputs/apk/
dummy-android-single-apk-dev-debug.apk
dummy-android-single-apk-dev-debug-unaligned.apk
dummy-android-single-apk-dev-release-unsigned.apk
dummy-android-single-apk-tst-debug.apk
dummy-android-single-apk-tst-debug-unaligned.apk
dummy-android-single-apk-tst-release-unsigned.apk

对于我的图书馆项目

Artifactory repo(上传所有4个变种):

enter image description here

生成的依赖配置(分类器设置)

<dependency>
    <groupId>eu.dorsum.cm.dummy.android</groupId>
    <artifactId>gradle-android-aar</artifactId>
    <version>1.0.0-20170208.200531-1</version>
    <classifier>devDebug</classifier>
    <type>aar</type>
</dependency>
<dependency>
    <groupId>eu.dorsum.cm.dummy.android</groupId>
    <artifactId>gradle-android-aar</artifactId>
    <version>1.0.0-20170208.200531-1</version>
    <classifier>devRelease</classifier>
    <type>aar</type>
</dependency>
<dependency>
    <groupId>eu.dorsum.cm.dummy.android</groupId>
    <artifactId>gradle-android-aar</artifactId>
    <version>1.0.0-20170208.200531-1</version>
    <classifier>tstDebug</classifier>
    <type>aar</type>
</dependency>
<dependency>
    <groupId>eu.dorsum.cm.dummy.android</groupId>
    <artifactId>gradle-android-aar</artifactId>
    <version>1.0.0-20170208.200531-1</version>
    <classifier>tstRelease</classifier>
    <type>aar</type>
</dependency>

内置二进制文件

$ ls -1 build/outputs/aar/
gradle-android-aar-dev-debug.aar
gradle-android-aar-dev-release.aar
gradle-android-aar-tst-debug.aar
gradle-android-aar-tst-release.aar

0 个答案:

没有答案