【问题标题】:Deploy from Maven to JFrog Artifactory WITH properties使用属性从 Maven 部署到 JFrog Artifactory
【发布时间】:2017-11-05 09:11:37
【问题描述】:

我有一份 Jenkins 工作,它有 REPOSITORY 和 BRANCH 输入变量和用途 调用顶级 Maven 目标 插件。它使 maven 干净地部署到 jfrog 工件。

但是有一个问题:我不知道如何将属性发送到已部署的工件。我的意思是像这样的属性,我们在 JFROG ARTIFACTORY 中拥有:

我知道,有 Maven3-Artifactory Integration 插件可以使用属性进行部署,但在我的情况下它不起作用,因为我的工作应该适用于不同的工件服务器。

我还在Invoke top-level Maven targets中找到了一个参数Properties 但它什么也没做(已部署工件的属性列表仍然为空)

如何通过 maven 调用顶级 Maven 目标插件向 JFROG ARTIFACTORY 发送属性?提前致谢。

【问题讨论】:

  • 从我的角度来看,拥有不同的工件存储库是有意义的,但不同的工件服务器听起来不对...?
  • 就我而言,我可以同时拥有不同的工件存储库和工件服务器。因此可以根据项目的 pom.xml 将工件部署到不同的服务器。
  • 为什么不使用 Jenkins Artifactory 插件? wiki.jenkins-ci.org/display/JENKINS/Artifactory+Plugin
  • 因为变量“artifactory server”和“repository”(部署目标)是动态的。这个 Jenkins 作业是为许多 git 项目(git repos)创建的,它根据“git repo”输入变量(并根据里面的 pom.xml 文件)部署到不同的工件和不同的 repos。
  • 好的,那为什么不使用 Pipeline 构建呢?它是灵活和动态的。 Jenkins Artifactory Plugin 也支持 Pipeline。

标签: maven jenkins artifactory jfrog-mission-control


【解决方案1】:

考虑到您需要动态控制目标存储库以进行部署,您有多种选择:

1) 使用 Artifactory Jenkins 插件的pipeline support。管道 DSL 允许您动态控制用于Maven 解析/部署的存储库,例如:

def rtMaven = Artifactory.newMavenBuild() 
rtMaven.resolver server: server, releaseRepo: 'libs-release', snapshotRepo: 'libs-snapshot' 
rtMaven.deployer server: server, releaseRepo: 'libs-release-local', snapshotRepo: 'libs-snapshot-local'

并添加属性:

rtMaven.deployer.addProperty("status", "in-qa").addProperty("compatibility", "1", "2", "3")

2) 使用Artifactory Maven plugin,它允许您从 pom.xml 定义分辨率/部署和属性。您还可以利用environment variables or system properties 以动态方式定义它们。 例如:

<build>
    <plugins>
        ...
        <plugin>
            <groupId>org.jfrog.buildinfo</groupId>
            <artifactId>artifactory-maven-plugin</artifactId>
            <version>2.6.1</version>
            <inherited>false</inherited>
            <executions>
                <execution>
                    <id>build-info</id>
                    <goals>
                        <goal>publish</goal>
                    </goals>
                    <configuration>
                        <deployProperties>
                            <build.name>{{BUILD_NAME}}</build.name>
                        </deployProperties>
                        <publisher>
                            <contextUrl>https://artifactory.mycompany.com</contextUrl>
                            <username>deployer</username>
                            <password>******</password>
                            <repoKey>{{RELEASE_REPO}}</repoKey>
                            <snapshotRepoKey>{{SNAPSHOT_REPO}}</snapshotRepoKey>
                        </publisher>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

3) 正如@viniciusartur 已经回答的那样,您可以在存储库URL 中使用matrix parameters 来定义属性

【讨论】:

    【解决方案2】:

    您可以使用 Matrix Properties 在部署时分配 JFrog Artifactory 属性。

    您只需在分发 URL 上附加“;property1=value1;property2=value2”,如下所示:

    <distributionManagement>
        <repository>
            <id>myrepo</id>
            <url>http://localhost:8080/artifactory/libs-release-local;property1=value1;property2=value2</url>
        </repository>
    </distributionManagement>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-18
      • 1970-01-01
      • 1970-01-01
      • 2023-01-21
      • 1970-01-01
      • 1970-01-01
      • 2018-06-21
      相关资源
      最近更新 更多