使用属性从 Maven 部署到 JFrog Artifactory
Deploy from Maven to JFrog Artifactory WITH properties
我有一个 Jenkins 作业,它有 REPOSITORY 和 BRANCH 输入变量并使用
调用顶级 Maven 目标 插件。它使 maven 干净部署到 jfrog artifactory。
但是有一个问题:我不知道如何将属性发送到已部署的工件。我的意思是像这样的属性,我们在 JFROG ARTIFACTORY 中拥有:
我知道,有 Maven3-Artifactory Integration 插件可以使用属性进行部署,但它在我的情况下不起作用,因为我的工作应该是通用的不同的神器服务器。
我还在Invoke top-level Maven targets中找到了参数Properties
但它什么都不做(已部署工件的属性列表仍然是空的)
如何通过 maven 将属性发送到 JFROG ARTIFACTORY 调用顶级 Maven 目标插件?提前致谢。
您可以使用 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>
考虑到您需要动态控制部署的目标存储库,您有多种选择:
1) 使用pipeline support of the Artifactory Jenkins plugin. The pipeline DSL allows you to dynamically control the repositories you are using for Maven resolution/deployment,例如:
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 which allows you to define the resolution/deployment and properties from the pom.xml. You can also leverage 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 来定义属性
我有一个 Jenkins 作业,它有 REPOSITORY 和 BRANCH 输入变量并使用 调用顶级 Maven 目标 插件。它使 maven 干净部署到 jfrog artifactory。
但是有一个问题:我不知道如何将属性发送到已部署的工件。我的意思是像这样的属性,我们在 JFROG ARTIFACTORY 中拥有:
我知道,有 Maven3-Artifactory Integration 插件可以使用属性进行部署,但它在我的情况下不起作用,因为我的工作应该是通用的不同的神器服务器。
我还在Invoke top-level Maven targets中找到了参数Properties
如何通过 maven 将属性发送到 JFROG ARTIFACTORY 调用顶级 Maven 目标插件?提前致谢。
您可以使用 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>
考虑到您需要动态控制部署的目标存储库,您有多种选择:
1) 使用pipeline support of the Artifactory Jenkins plugin. The pipeline DSL allows you to dynamically control the repositories you are using for Maven resolution/deployment,例如:
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 which allows you to define the resolution/deployment and properties from the pom.xml. You can also leverage 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 来定义属性