Jenkins的自动化脚本记录

Posted by Epoch Blog on December 7, 2021

脚本文件Jenkinsfile

1
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
pipeline {
	
	tools {
		maven 'maven'
	}

	agent any
    //构建流水线
	stages {
	    // check工程
		stage('SCM') {
			steps{
				timestamps{
					checkout([$class: 'GitSCM', branches: [[name: '*/dev']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'db41fe72-b740-4ff2-aaf4-73b6f64618c7', url: 'https://gitee.com/EpochGroup/epoch.git']]])
				}
				
			}
		}
		//打包,打成zip包
		stage('Build And Test	') {
			steps{
				timestamps{
					sh "mvn clean package"
					sh """
						zip -q -r epoch.zip "target/epochOpen.war"
					"""
				}
				
			}
		}
		//sonar构建
		stage('Sonar') {
			steps{
				timestamps {
					sh "mvn sonar:sonar  -Dsonar.projectKey=epoch -Dsonar.host.url=http://119.3.250.100:9000  -Dsonar.login=4343b554d97149e48f7788b6cdb3d46824f889af"
				}
			}
		}
		//Artifactory是一个产品管理工具
		stage ('Artifactory configuration') {
			steps{
				timestamps {
					script{ 
						def SERVER_ID = '6888' 
						def server = Artifactory.server SERVER_ID
						def uploadSpec = 
						"""
						{
						"files": [
							{
								"pattern": "epochOpen/epoch.zip",
								"target": "epoch/${BUILD_NUMBER}/"
							},
							{
								"pattern": "epoch.zip",
								"target": "epoch/${BUILD_NUMBER}/"
							}
						  ]
						}
						"""
						def buildInfo = Artifactory.newBuildInfo()
						buildInfo.env.capture = true
						buildInfo = server.upload(uploadSpec)
						server.publishBuildInfo(buildInfo)
					}
				}
			}
		}
		
	}
}