I've my .Jenkinsfile like this:
properties([[$class: 'GitLabConnectionProperty', gitLabConnection: 'gitlab@srv']])
node {
env.JAVA_HOME = tool 'JDK 7'
def mvnHome = tool 'Maven 3.2.2'
def nodeJS = tool 'IA_NodeJS'
env.PATH = "${mvnHome}/bin:${nodeJS}/bin:${env.JAVA_HOME}/bin:${env.PATH}"
stage ('checkout') {
checkout scm
}
stage ('build') {
gitlabCommitStatus("build") {
// your build steps
sh 'mvn clean install -Denv=dev -P !faster'
}
}
stage ('upload') {
gitlabCommitStatus("upload") {
def server = Artifactory.server "artifactory@ibsrv02"
def buildInfo = Artifactory.newBuildInfo()
buildInfo.env.capture = true
buildInfo.env.collect()
def uploadSpec = """{
"files": [
{
"pattern": "**/target/*.jar",
"target": "libs-snapshot-local"
}, {
"pattern": "**/target/*.pom",
"target": "libs-snapshot-local"
}, {
"pattern": "**/target/*.war",
"target": "libs-snapshot-local"
}
]
}"""
// Upload to Artifactory.
server.upload spec: uploadSpec, buildInfo: buildInfo
buildInfo.retention maxBuilds: 10, maxDays: 7, deleteBuildArtifacts: true
// Publish build info.
server.publishBuildInfo buildInfo
}
}
}
with this method jenkins uploads artifacts without make the "maven's style" layout (packages subfolder and poms).
I want to upload resulting artifact to Artifactory like a normal job uploads it with "Maven3-Artifactory Integration" checked.
For example, to pull Artifactory every ten minutes, set */10 * * * * 4. Set a Path to watch. For example, when setting generic-libs-local/builds/starship, Jenkins polls the /builds/starship folder under the generic-libs-local repository in Artifactory for new or modified files.
The Jenkins Artifactory Plugin supports the following Jenkins Build Jobs: JFrog Pipelines integration with Jenkins is supported since version 1.6 of JFrog Piplines and version 3.7.0 of the Jenkins Artifactory Plugin. This integration allows triggering a Jenkins job from JFrog Pipelines.
There's a Maven Artifactory plugin that will connect to the Artifactory repository as part of a successful build. Simply issue a Maven deploy command as part of the build, and if the Maven plugin is configured correctly, the artifact it produces will be uploaded.
For organizations in pursuit of DevOps enlightenment, it's the CI/CD build that should be pushing packaged artifacts to an Artifactory repository. Fortunately, JFrog provides a Jenkins Artifactory plugin that facilitates automation of the process.
From Artifactory Jenkins plugin version 2.7.2 you can run Maven and Gradle using Artifactory pipeline DSL.
Using the new DSL your build script would look like this:
def server = Artifactory.server "artifactory@ibsrv02"
def buildInfo = Artifactory.newBuildInfo()
buildInfo.env.capture = true
def rtMaven = Artifactory.newMavenBuild()
rtMaven.tool = MAVEN_TOOL // Tool name from Jenkins configuration
rtMaven.opts = "-Denv=dev"
rtMaven.deployer releaseRepo:'libs-release-local', snapshotRepo:'libs-snapshot-local', server: server
rtMaven.resolver releaseRepo:'libs-release', snapshotRepo:'libs-snapshot', server: server
rtMaven.run pom: 'pom.xml', goals: 'clean install', buildInfo: buildInfo
buildInfo.retention maxBuilds: 10, maxDays: 7, deleteBuildArtifacts: true
// Publish build info.
server.publishBuildInfo buildInfo
You can find more Artifactory pipeline DSL examples in the jenkins-pipeline-examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With