1
votes

In a scripted Jenkins pipeline I used the following functionality:

rtMaven.deployer.artifactDeploymentPatterns.addInclude("frog*")

What is the equivalent way to do it in a declarative pipeline?

The declarative examples on the wiki makes no mention of it, whereas the scripted examples do.

Clearly, looking at the souce of the plugin, the functionalty I want is there, and I don't know how to invoke it.

https://github.com/jfrog/jenkins-artifactory-plugin/blob/ebce86efdf1e1a7c38a9ad1ed6a8063b58ecdf3a/src/main/java/org/jfrog/hudson/pipeline/declarative/steps/maven/MavenDeployerStep.java#L26

Working, scripted code:

server = Artifactory.server("myServer")
rtMaven = Artifactory.newMavenBuild()
rtMaven.tool = config.toolMaven // Tool name from Jenkins configuration
rtMaven.deployer releaseRepo: "libs-release-local", snapshotRepo: "libs-snapshot-local", server: server
rtMaven.resolver releaseRepo: "libs-release", snapshotRepo: "libs-snapshot", server: server
rtMaven.deployer.deployArtifacts = false // Disable artifacts deployment during Maven run
if (config.includeFilterPattern) {
    rtMaven.deployer.artifactDeploymentPatterns.addInclude(config.includeFilterPattern)
}
buildInfo = Artifactory.newBuildInfo()
buildInfo.name = "myBuild"
buildInfo.env.capture = true

My declarative code currently looks like this:

rtMavenResolver (
        id: "resolver-id",
        serverId: "myServer",
        releaseRepo: "libs-release",
        snapshotRepo: "libs-snapshot"
)

rtMavenDeployer (
        id: "deployer-id",
        serverId: "myServer",
        releaseRepo: "libs-release-local",
        snapshotRepo: "libs-snapshot-local"
)

rtBuildInfo (
        captureEnv: true,
        buildName: "myBuild"
)

//... mvn clean install

rtPublishBuildInfo (
        serverId: "myServer"
)
1
Just wrap the call in a script{ } block.zett42
Also from the doc: "When working with the Jenkins Artifactory plugin, be sure to choose either scripted or declarative. In other words, do not use declarative and scripted steps within a single pipeline. This will not work."Denham Coote
So, thanks, but unless you've got a working example, I don't think it's as simple as thatDenham Coote
How I read that is that you should not mix declarative and scripted steps of Artifactory but you are still allowed to use all-scripted Artifactory steps in a declarative pipeline. So you could basically do everything as you were used in scripted pipeline, except that you wrap that code in script blocks. Might not be as "clean" as pure declarative syntax but you could always wrap scripted code into your own higher-level declarative steps defined in a shared library.zett42
That I agree with, and have done so in the past. I guess this is more an exercise of using the pure-declaritive style, and finding it lacking.Denham Coote

1 Answers

1
votes

Very simple once you know how (Not documented at the time of writing):

rtMavenDeployer (
        id: "deployer-id",
        serverId: "myServer",
        releaseRepo: "libs-release-local",
        snapshotRepo: "libs-snapshot-local",
        includePatterns: ["frog*"]
)