-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile_Artifactory
More file actions
73 lines (65 loc) · 2.9 KB
/
Jenkinsfile_Artifactory
File metadata and controls
73 lines (65 loc) · 2.9 KB
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
72
73
pipeline {
agent { label 'docker' }
environment {
projectname = JOB_NAME.toLowerCase()
}
stages {
stage ('Pipeline configuration') {
agent none
steps {
script {
def server = Artifactory.server('artifactory')
def rtMaven = Artifactory.newMavenBuild()
def buildInfo
def version = "${env.BUILD_NUMBER}"
def port=9191
def dockerNetwork="devopscoc-demotoolchain_default"
stage('Java Build') {
// resolver is used for downloading dependencies
// rtMaven.resolver server: server, releaseRepo: 'maven', snapshotRepo: 'maven'
rtMaven.deployer server: server, releaseRepo: 'example-repo-local', snapshotRepo: 'example-repo-local'
rtMaven.tool = "maven"
buildInfo = rtMaven.run pom: 'pom.xml', goals: 'clean package -Dmaven.test.skip=true'
}
stage('Publish to Artifactory') {
server.publishBuildInfo buildInfo
}
stage('JUnit') {
try {
buildInfo = rtMaven.run pom: 'pom.xml', goals: 'test'
} finally {
junit allowEmptyResults: true, testResults: '**/target/surefire-reports/*.xml'
}
}
stage('QA') {
withSonarQubeEnv('sonar') {
buildInfo = rtMaven.run pom: 'pom.xml', goals: 'sonar:sonar'
}
}
stage('Sonarqube Quality Gate') {
sleep 20
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
stage('Build Dockerimage') {
docker.withServer('tcp://socatdockersock:2375') {
def customImage = docker.build("${projectname}:${version}")
}
}
stage('Deploy') {
docker.withServer('tcp://socatdockersock:2375') {
// stop old container, if no container is running, exit with true
sh 'docker stop "$(docker ps -qf name=deploy-${projectname})" || true'
// deploy fresh container
sh """docker run --net ${dockerNetwork} \
--name deploy-${projectname}${version} -d -p ${port}:${port} ${projectname}:${version}"""
}
echo "Application was deployed on http://localhost:${port}"
}
}
}
}
}
}