实现环境
通过Jenkins Job从Github获取代码并用Maven Build。
说明: 这里只用了一个Server, 用到的工具都安装在此
Jenkins安运行,请参考Jenkins安装
在Github创建一个Repository
代码:1
2
3
4
5
6
7
8
9
10
11package artifactory;
public class MavenSample {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("This for testing artifactory, github and jenkins");
}
}安装/升级Maven,并做以下配置(Global Tool Configuration)
- 安装/升级Git,并做以下配置(Global Tool Configuration)
- 配置JDK(Global Tool Configuration)
创建一个Jenkins Pipeline Job
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22node {
def mvnHome
stage('Preparation') { // for display purposes
// Get some code from a GitHub repository
git 'https://www.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('Results') {
archive 'target/*.jar'
}
}运行Job
最基本的配置好了,接下来会配置当Github有Commit时Job自动运行。