Goal
When Github have commit,will trigger Jenkins job to upload artifact to artifactory.
Prerequisites
Artifactory installation and running,please refer: Artifactory
Config Artifactory with Jenkins
Jenkins > Manage Jenkins > Configure System
Update Pipeline Script
Add script for uploading Artifact1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34node {
def mvnHome
def baseArtifactoryUrl = 'com/izheyi/yongfeiuall'
def artifactoryServer = Artifactory.server 'artifact-jenkins'
stage('Preparation') { // for display purposes
// Get some code from a GitHub repository
git credentialsId: 'ee7a726b-e672-424d-9b78-e8015668d55a', url: 'https://github.com/yongfeiuall/artifactory-maven-example.git'
// Get the Maven tool.
// ** NOTE: This 'M3' Maven tool must be configured
// ** in the global configuration.
mvnHome = tool 'M3'
}
stage('Build') {
// Run the maven build
if (isUnix()) {
sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore clean package"
} else {
bat(/"${mvnHome}\bin\mvn" -Dmaven.test.failure.ignore clean package/)
}
}
stage('publish release build to artifactory') {
def uploadSpec = """
{
"files": [{
"pattern": "target/*.jar",
"target": "libs-release-local/${baseArtifactoryUrl}/test/"
}]
}
"""
def buildInfo = artifactoryServer.upload(uploadSpec)
artifactoryServer.publishBuildInfo buildInfo
}
}
Verify Uploadiing
- Run jenkins job
- Check on Artifactory