3

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.

dice2011
  • 937
  • 2
  • 15
  • 30
  • Having different artifact repositories make sense from my point of view but different artifactory servers sounds wrong...? – khmarbaise Jun 04 '17 at 13:38
  • 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 Jun 05 '17 at 06:30
  • Why not using Jenkins Artifactory plugin? https://wiki.jenkins-ci.org/display/JENKINS/Artifactory+Plugin – Ariel Jun 05 '17 at 12:24
  • 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 Jun 05 '17 at 12:29
  • 3
    Ok, so why not using the Pipeline build? It's flexible and dynamic. Jenkins Artifactory Plugin also has support for Pipeline. – Ariel Jun 05 '17 at 12:31
  • Don’t understand, how can I realize it: We have a job, that makes “maven clean deploy” to the given project. It makes deploy to the target artifactory, according to a *pom.xml* of a repo (repo's name is in input). Everything could be great, but all the artifacts in the artifactory are deployed without properties. We could make just “maven install” and deploy these artifacts by plugin. But as I see, I need to set manually inside of plugin, what exactly do I want to deploy, right? And “Jenkins Artifactory Plugin” still has determined server and targetrepo. How can it work in my case? – dice2011 Jun 05 '17 at 12:49

2 Answers2

4

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

Dror Bereznitsky
  • 20,048
  • 3
  • 48
  • 57
0

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>