首页 文章

从Maven部署到JFrog Artifactory WITH属性

提问于
浏览
2

我有一个Jenkins工作,它有REPOSITORY和BRANCH输入变量并使用 Invoke top-level Maven targets 插件 . 它使maven干净地部署到jfrog神器 .

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

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

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

如何通过maven Invoke top-level Maven targets plugin 将属性发送到JFROG ARTIFACTORY?提前致谢 .

2 回答

  • 2

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

    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来定义属性

  • 0

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

    您只需要在分发网址上附加'; property1 = value1; property2 = value2',如下所示:

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

相关问题