从Jenkins发布到Artifactory时如何指定模块名称

时间:2014-05-29 23:45:55

标签: maven jenkins gradle artifactory

我正在使用此处记录的gradle artifactory发布插件:http://www.jfrog.com/confluence/display/RTF/Gradle+1.6+Publishing+Artifactory+Plugin

我正在使用完全按照文档中所述的标准配置。

当我从命令行运行gradle publishArtifactory任务时,我得到这样的输出。即它部署到我正确的模块名称。

Deploying artifact: http://<my server>/artifactory/libs-snapshot-local/<my actual module name>/web/0.1-SNAPSHOT/web-0.1-SNAPSHOT.war

当我将Jenkins配置为使用相同的gradle构建文件运行gradle publishArtifactory任务时,我得到这样的输出。即它使用Jenkins构建作为模块名称。

Deploying artifact: http://artifactory01.bcinfra.net:8081/artifactory/libs-snapshot-local/<the name of the jenkins build>/web/0.1-SNAPSHOT/web-0.1-SNAPSHOT.war

有关如何防止神器插件使用Jenkins构建名称作为模块名称的任何想法?

2 个答案:

答案 0 :(得分:9)

用于上载的模块名称源自gradle项目名称。 gradle项目名称的默认值取自项目文件夹名称。我怀疑在你的jenkins工作中,你将你的代码检查到一个名为你的构建工作的文件夹中。这就是为什么默认情况下这个文件夹名称用作项目名称。

最干净的解决方案是在gradle中明确设置项目名称。

因此,您需要项目根文件夹中包含项目名称的settings.gradle文件:

rootProject.name = "web" 

答案 1 :(得分:3)

你也可以单独让Gradle发布到Artifactory,而不需要在Jenkins中使用Artifactory插件。

这样,您可以使用artifactId "your artifact name"设置工件的名称,而无需将项目的名称更改为suggested by Rene Groeschke

我的publish.gradle证明了这一点:

buildscript {
  repositories {
    jcenter() 
  }
  dependencies {
    classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1"
  }
}
// Because this is a helper script that's sourced in from a build.gradle, we can't use the ID of external plugins
// We either use the full class name of the plugin without quotes or an init script: http://www.gradle.org/docs/current/userguide/init_scripts.html
apply plugin: org.jfrog.gradle.plugin.artifactory.ArtifactoryPublicationsPlugin

// Pack the sources into a jar
task sourceJar(type: Jar) {
  from sourceSets.main.allSource; classifier = "sources" 
}

// Pack the Javadoc into a jar
task javadocJar(type: Jar) {
  from javadoc.outputs.files; classifier = "javadoc" 
}

apply plugin: "maven-publish"

publishing {
  publications {
    mavenJava(MavenPublication){
      from components.java

      // Set the base name of the artifacts
      artifactId "your artifact name"

      artifact jar
      artifact sourceJar
      artifact javadocJar
    }
  }
}

artifactory {
  contextUrl = "http://localhost:8081/artifactory"

    publish {
      // Publish these artifacts
      defaults{ publications ("mavenJava") }

      repository {
        repoKey = "libs-release-local"
        // Provide credentials like this:
        //-Partifactory.publish.password=yourPassword
        //-Partifactory.publish.username=yourUsername
      }
    }
  resolve {
    repository {
      repoKey = "libs-release"
    }
  }
}

您可以通过build.gradleapply from: "path/to/publish.gradle"中使用此脚本,并将其命名为:

./gradlew artifactoryPublish -Partifactory.publish.username="yourUsername" -Partifactory.publish.password="yourPassword"