如何设置Jenkinsfile用于上传maven工件到Artifactory



我的。jenkinsfile如下:

properties([[$class: 'GitLabConnectionProperty', gitLabConnection: 'gitlab@srv']])
node {
  env.JAVA_HOME = tool 'JDK 7'
  def mvnHome = tool 'Maven 3.2.2'
  def nodeJS = tool 'IA_NodeJS'
  env.PATH = "${mvnHome}/bin:${nodeJS}/bin:${env.JAVA_HOME}/bin:${env.PATH}"
  stage ('checkout') {
    checkout scm
  }
  stage ('build') {
    gitlabCommitStatus("build") {
      // your build steps
      sh 'mvn clean install -Denv=dev -P !faster'
    }
  }
  stage ('upload') {
    gitlabCommitStatus("upload") {
      def server = Artifactory.server "artifactory@ibsrv02"
      def buildInfo = Artifactory.newBuildInfo()
      buildInfo.env.capture = true
      buildInfo.env.collect()
      def uploadSpec = """{
        "files": [
          {
            "pattern": "**/target/*.jar",
            "target": "libs-snapshot-local"
          }, {
            "pattern": "**/target/*.pom",
            "target": "libs-snapshot-local"
          }, {
            "pattern": "**/target/*.war",
            "target": "libs-snapshot-local"
          }
        ]
      }"""
      // Upload to Artifactory.
      server.upload spec: uploadSpec, buildInfo: buildInfo
      buildInfo.retention maxBuilds: 10, maxDays: 7, deleteBuildArtifacts: true
      // Publish build info.
      server.publishBuildInfo buildInfo
    }
  }
}

使用这个方法,Jenkins上传工件时不需要做"maven的样式"布局(packages子文件夹和poms)。

我想把结果工件上传到Artifactory,就像一个正常的作业上传它与"Maven3-Artifactory集成"选中。

从Artifactory Jenkins插件2.7.2版本开始,你可以使用Artifactory管道DSL来运行Maven和Gradle。

使用新的DSL,您的构建脚本看起来像这样:

  def server = Artifactory.server "artifactory@ibsrv02"
  def buildInfo = Artifactory.newBuildInfo()
  buildInfo.env.capture = true
  def rtMaven = Artifactory.newMavenBuild()
  rtMaven.tool = MAVEN_TOOL // Tool name from Jenkins configuration
  rtMaven.opts = "-Denv=dev"
  rtMaven.deployer releaseRepo:'libs-release-local', snapshotRepo:'libs-snapshot-local', server: server
  rtMaven.resolver releaseRepo:'libs-release', snapshotRepo:'libs-snapshot', server: server
  rtMaven.run pom: 'pom.xml', goals: 'clean install', buildInfo: buildInfo
  buildInfo.retention maxBuilds: 10, maxDays: 7, deleteBuildArtifacts: true
  // Publish build info.
  server.publishBuildInfo buildInfo

您可以在jenkins-pipeline-examples中找到更多人工管道DSL示例。

相关内容

  • 没有找到相关文章

最新更新