使用属性从Maven部署到JFrog Artifactory
我有一份Jenkins的工作,有存储库和分支输入变量,并使用 调用顶级Maven目标插件。它使maven能够干净地部署到jfrog artifactory 但有一个问题:我不知道如何将属性发送到已部署的工件。我的意思是像这样的属性,我们在JFROG ARTIFACTORY中拥有: 我知道,有一个Maven3 Artifactory Integration插件可以使用属性进行部署,但在我的情况下它不起作用,因为我的工作应该是针对不同的Artifactory服务器的常规工作 我还在调用顶级Maven目标中找到了一个参数Properties 但它什么也不做(已部署工件的属性列表仍然为空)使用属性从Maven部署到JFrog Artifactory,maven,jenkins,artifactory,jfrog-mission-control,Maven,Jenkins,Artifactory,Jfrog Mission Control,我有一份Jenkins的工作,有存储库和分支输入变量,并使用 调用顶级Maven目标插件。它使maven能够干净地部署到jfrog artifactory 但有一个问题:我不知道如何将属性发送到已部署的工件。我的意思是像这样的属性,我们在JFROG ARTIFACTORY中拥有: 我知道,有一个Maven3 Artifactory Integration插件可以使用属性进行部署,但在我的情况下它不起作用,因为我的工作应该是针对不同的Artifactory服务器的常规工作 我还在调用顶级Mave
如何通过maven调用顶级maven目标插件将属性发送到JFROG ARTIFACTORY?提前感谢。您可以使用在部署时分配JFrog Artifactory属性 您只需要附加';财产1=价值1;发布URL上的property2=value2',如下所示:
<distributionManagement>
<repository>
<id>myrepo</id>
<url>http://localhost:8080/artifactory/libs-release-local;property1=value1;property2=value2</url>
</repository>
</distributionManagement>
myrepo
http://localhost:8080/artifactory/libs-局部释放;财产1=价值1;属性2=值2
考虑到您需要动态控制目标存储库以进行部署,您有多种选择:
1) 使用Artifactory Jenkins插件的。管道DSL允许您动态控制用于解决/部署的存储库,例如:
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'
<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>
并添加属性:
rtMaven.deployer.addProperty("status", "in-qa").addProperty("compatibility", "1", "2", "3")
2) 使用允许您从pom.xml定义解析/部署和属性的。您还可以利用以动态方式定义它们。
例如:
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'
<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>
...
org.jfrog.buildinfo
在存储库URL中定义属性在我看来,拥有不同的工件存储库是有意义的,但不同的工件服务器听起来是错误的…?在我的案例中,我可以拥有不同的工件存储库和工件服务器。因此,根据项目的pom.xml,工件可以部署到不同的服务器上。为什么不使用Jenkins工件插件呢?因为变量“artifactoryserver”和“repository”(部署目标)是动态的。这个Jenkins作业是为许多git项目(git repo)创建的,它根据“git repo”输入变量(以及其中的pom.xml文件)部署到不同的工件和不同的repo?它是灵活和动态的。Jenkins Artifactory插件还支持管道。