首页 文章

如何将Jenkins的特定工件部署到Nexus?

提问于
浏览
2

我有一个在Jenkins运行的多模块maven项目 . 我想将最终工件(来自程序集构建的RPM)部署到Nexus服务器 . 我认为没有理由部署中间工件(因此没有“mvn clean deploy”),因为这会在我不需要的服务器上产生额外的垃圾 . 我们正在尝试 Build 一个持续的交付管道,因此我们不会部署SNAPSHOT版本 . Jenkins的各种插件似乎专注于部署所有工件 . 我怎样才能部署我选择的那个?

编辑:

经过深思熟虑后,如果部署在所有构建完成后发生,我愿意将所有工件部署到nexus . 如果我要走那条路,我想在构建操作后使用“部署工件到maven存储库” . 这个工具似乎破了,因为它缺少指定用户名/密码的功能 . 我知道这可以在settings.xml中指定,但显然只能在“.m2”中指定 . 它似乎没有查看我为此构建指定的settings.xml .

对于重新部署工件,这似乎也被打破了 . 在"Jenkins the Definitive Guide"中有一些verbage,但它讨论的是"local" settings.xml . 我所有的构建都发生在Jenkins的奴隶身上,所以这对于Jenkins架构来说甚至没有意义 .

4 回答

  • 0

    如果你还需要通用方式 .

    使用Execute shell选项并手动使用mvn deploy命令,你可以将你的版本和其他东西(例如groupID等)作为参数传递给作业,如果你维护单独的作业来构建和上传,这将有效 .

    例如:

    export M2_HOME = / PATH / TO / softwares / apache-maven-3.0.4 PATH = $ M2_HOME / bin:$ JAVA_HOME / bin:$ PATH export PATH

    mvn -v

    mvn deploy:deploy-file -Durl = http://someorg:8081/nexus/content/repositories/t1.snapshot/ -DrepositoryId = t1.snapshot -DartifactId = artifactID -DgroupId = groupID -Dpackaging = zip -Dfile = $ /filename.zip -Dversion = 1.0-TEST-SNAPSHOT -s "/path/to/.m2/settings.xml"

  • 0

    您可以在'Post-Build Actions'下使用'Deploy artifacts to Maven Repository' . 看看这个answer

  • 1

    这是我提出的丑陋黑客 . 如果有人有更好的想法,我很乐意给别人一个“正确”的答案:

    我意识到我需要部署父pom.xml和程序集 . 我是在两个单独的后期构建步骤中完成的 .

    首先,我使用Maven版本的“Maven”选择“调用顶级Maven目标”(我认为这使用了Jenven版本的maven . 我不想在系统上放置不同的版本) . 我使用的目标是:

    -s svn-admin/settings.xml -N deploy
    

    使用我指定的settings.xml将父pom部署到nexus .

    当我想部署rpm时,真正的大黑客就会发生 . 我尝试了一个"deploy-file"目标,但是如果没有变量我可以扩展到版本号,我就不能扩展了.2623986_ t . 相反,我做了一个"Execute shell"选项并使用curl我找到here

    env
    UPLOAD_FILE=assembly/target/ips-${POM_VERSION}-x.x86_64.rpm
    DESTINATION=http://mvnrepo01/nexus/content/repositories/releases/com/bla/ips/assembly/${POM_VERSION}/assembly-${POM_VERSION}.rpm
    sha1sum ${UPLOAD_FILE} | awk -F" " '{print $1}' | curl -v -u admin:password --upload-file - ${DESTINATION}.sha1
    md5sum ${UPLOAD_FILE} | awk -F" " '{print $1}' | curl -v -u admin:password --upload-file - ${DESTINATION}.md5
    curl -v -u admin:password --upload-file ${UPLOAD_FILE} ${DESTINATION}
    
    UPLOAD_FILE=assembly/pom.xml
    DESTINATION=http://mvnrepo01/nexus/content/repositories/releases/com/bla/ips/assembly/${POM_VERSION}/assembly-${POM_VERSION}.pom
    sha1sum ${UPLOAD_FILE} | awk -F" " '{print $1}' | curl -v -u admin:password --upload-file - ${DESTINATION}.sha1
    md5sum ${UPLOAD_FILE} | awk -F" " '{print $1}' | curl -v -u admin:password --upload-file - ${DESTINATION}.md5
    curl -v -u admin:password --upload-file ${UPLOAD_FILE} ${DESTINATION}
    

    就像我说的,这是一个丑陋的黑客 . 我很确定有些元数据文件没有得到更新,但rpm,它的pom和他们的校验和正在上传 .

  • 0

    您可以使用 Nexus Jenkins Plugin 将Jenkins中的特定工件部署到Nexus中:https://support.sonatype.com/hc/en-us/articles/227256688-How-do-I-configure-the-Nexus-Jenkins-Plugin

    Jenkins管道示例:

    stage('Publish') {
        def pom = readMavenPom file: 'pom.xml'
        nexusPublisher nexusInstanceId: 'your-nexus-instance-id', \
            nexusRepositoryId: 'your-nexus-repository-id', \
            packages: [[$class: 'MavenPackage', \
            mavenAssetList: [[classifier: '', extension: '', filePath: "target/${pom.artifactId}-${pom.version}.${pom.packaging}"]], \
            mavenCoordinate: [artifactId: "${pom.artifactId}", \
            groupId: "${pom.groupId}", \
            packaging: "${pom.packaging}", \
            version: "${pom.version}"]]]
    }
    

    在这种情况下,Nexus Jenkins插件只会将您的 target/${pom.artifactId}-${pom.version}.${pom.packaging}pom.xml 文件部署到Nexus存储库 .

相关问题