首页 > 解决方案 > 问:如何使用 groovy 管道将工件保存到 Nexus 存储库中?

问题描述

我的问题是关于将工件保存到存储库中。特别是,在为 Maven 项目(通过 Jenkins)执行构建管道之后,我试图上传到 Nexus Repository 工件和发布版本。

我想要这样做的唯一方法就是使用用 Groovy 编写的管道以便与 Jenkins 集成。

注意:我希望工件版本号始终相同,并且版本号动态更改(而不是手动)。

通常是否有命令或代码可以让我做到这一点?

标签: jenkinscontinuous-integrationrepositoryjenkins-pipelinenexus

解决方案


您处于错误的级别,这应该发生在 Maven 中。在 pom.xml 你需要。(更多在这里

<distributionManagement>
   <snapshotRepository>
      <id>nexus-snapshots</id>
      <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
   </snapshotRepository>
</distributionManagement>

然后在插件部分

<plugin>
   <artifactId>maven-deploy-plugin</artifactId>
   <version>2.8.2</version>
   <executions>
      <execution>
         <id>default-deploy</id>
         <phase>deploy</phase>
         <goals>
            <goal>deploy</goal>
         </goals>
      </execution>
   </executions>
</plugin>

你应该能够mvn clean deploy从你的管道中做。

编辑Nexus Artifact Uploader 插件 还有另一种方法

  nexusArtifactUploader {
    nexusVersion('nexus2')
    protocol('http')
    nexusUrl('localhost:8080/nexus')
    groupId('sp.sd')
    version("2.4.${env.BUILD_NUMBER}")
    repository('NexusArtifactUploader')
    credentialsId('44620c50-1589-4617-a677-7563985e46e1')
    artifact {
        artifactId('nexus-artifact-uploader')
        type('jar')
        classifier('debug')
        file('nexus-artifact-uploader.jar')
    }
    artifact {
        artifactId('nexus-artifact-uploader')
        type('hpi')
        classifier('debug')
        file('nexus-artifact-uploader.hpi')
    }
  }

推荐阅读