-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
83 lines (80 loc) · 2.6 KB
/
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
72
73
74
75
76
77
78
79
80
81
82
// Initialize a LinkedHashMap / object to share between stages
def pipelineContext = [:]
pipeline {
agent any
environment {
DOCKER_REPOSITORY = "raulsuarezdabo/tfm-devsecop-jenkins"
RC_BRANCH = 'develop'
RELEASE_BRANCH = 'main'
}
stages {
stage('Dependencies') {
agent {
docker {
image 'maven:3-alpine'
args '-v /root/.m2:/root/.m2'
}
}
steps {
echo 'Dependency stage'
script {
sh "echo 'Downloading dependencies...'"
sh "mvn install -DskipTests=true"
}
}
}
stage('Testing') {
agent {
docker {
image 'maven:3-alpine'
args '-v /root/.m2:/root/.m2'
}
}
steps {
echo 'Test stage'
script {
sh "echo 'JUnit testing...'"
sh "mvn test"
sh "echo 'Integration testing...'"
sh "mvn test -Dtest=IntegrationTest"
jacoco(execPattern: 'target/jacoco.exec')
}
}
}
stage('Publish Release') {
when {
anyOf {
branch RC_BRANCH
branch RELEASE_BRANCH
}
}
steps{
script {
if (env.BRANCH_NAME == RC_BRANCH) {
MSG_CASE = 'Publishing Release Candidate'
CONTAINER_VERSION = env.BUILD_NUMBER+'-RC'
} else if (env.BRANCH_NAME == RELEASE_BRANCH) {
MSG_CASE = 'Publishing Release'
CONTAINER_VERSION = env.BUILD_NUMBER
} else {
error "Pipeline error, impossible to create an image on branch ${env.BRANCH_NAME}"
}
echo MSG_CASE
dockerImage = docker.build(DOCKER_REPOSITORY)
docker.withRegistry("", "docker_hub_login") {
dockerImage.push("${CONTAINER_VERSION}")
}
echo "Container ${DOCKER_REPOSITORY}:${CONTAINER_VERSION} pushed: OK"
}
}
}
stage('Deploy') {
when {
branch 'main'
}
steps {
echo 'Deploying...not implemented yet'
}
}
}
}