dice2011
dice2011

Reputation: 1037

Deploy from Maven to JFrog Artifactory WITH properties

I have a Jenkins job, that has REPOSITORY and BRANCH input variables and uses Invoke top-level Maven targets plugin. It makes maven clean deploy to jfrog artifactory.

But there is a problem: I don't know, how to send properties to the artifacts, that were deployed. I mean properties like these, that we have in JFROG ARTIFACTORY: enter image description here

I know, that there is Maven3-Artifactory Integration plugin that makes a deploy with properties, but it doesn't work in my case, because my job should be general for different artifactory servers.

I also found a parameter Properties in Invoke top-level Maven targets enter image description here but it does nothing (the list of properties of deployed artifacts is still empty)

How can I send properties to JFROG ARTIFACTORY by maven Invoke top-level Maven targets plugin? Thanks in advance.

Upvotes: 3

Views: 3906

Answers (2)

Dror Bereznitsky
Dror Bereznitsky

Reputation: 20376

Taking into consideration you have a requirement to dynamically control the target repository for deployment, you have multiple option:

1) Use the pipeline support of the Artifactory Jenkins plugin. The pipeline DSL allows you to dynamically control the repositories you are using for Maven resolution/deployment, for example:

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'

And add properties:

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

2) Use the 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 to define those in a dynamic way. For example:

<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) As already answered by @viniciusartur, you can use matrix parameters in the repository URL to define properties

Upvotes: 4

viniciusartur
viniciusartur

Reputation: 161

You can assign JFrog Artifactory Properties on deployment using Matrix Properties.

You just need to append ';property1=value1;property2=value2' on your distribution URL, like this:

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

Upvotes: 1

Related Questions