3
votes

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.

2
Having different artifact repositories make sense from my point of view but different artifactory servers sounds wrong...? - khmarbaise
I can have both different artifact repositories and artifactory servers in my case. So the artifacts can be deployed to different servers, according to a pom.xml of the project. - dice2011
Why not using Jenkins Artifactory plugin? wiki.jenkins-ci.org/display/JENKINS/Artifactory+Plugin - Ariel
Because the variables "artifactory server" and "repository" (deployment target) are dynamic. This Jenkins job was created for a lot of git projects (git repos), it deploys to different artifactories and to different repos, according to "git repo" input variable (and according to a pom.xml file inside). - dice2011
Ok, so why not using the Pipeline build? It's flexible and dynamic. Jenkins Artifactory Plugin also has support for Pipeline. - Ariel

2 Answers

3
votes

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

0
votes

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>