-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
88 lines (80 loc) · 3.18 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
83
84
85
86
87
88
pipeline {
agent any
environment {
IMAGE_NAME = "eeacms/bise-backend"
GIT_NAME = "bise-backend"
SONARQUBE_TAG = 'biodiversity.europa.eu'
}
parameters {
string(defaultValue: '', description: 'Run tests with GIT_BRANCH env enabled', name: 'TARGET_BRANCH')
}
stages {
stage('Build & Test') {
environment {
TAG = BUILD_TAG.toLowerCase()
}
steps {
node(label: 'docker') {
script {
try {
checkout scm
sh '''docker build -t ${IMAGE_NAME}:${TAG} .'''
sh '''./test/run.sh ${IMAGE_NAME}:${TAG}'''
} finally {
sh script: "docker rmi ${IMAGE_NAME}:${TAG}", returnStatus: true
}
}
}
}
}
stage('Release on tag creation') {
when {
buildingTag()
}
steps{
node(label: 'docker') {
withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN'), string(credentialsId: 'bise-backend-trigger', variable: 'TRIGGER_MAIN_URL'), usernamePassword(credentialsId: 'jekinsdockerhub', usernameVariable: 'DOCKERHUB_USER', passwordVariable: 'DOCKERHUB_PASS')]) {
sh '''docker pull eeacms/gitflow; docker run -i --rm --name="$BUILD_TAG" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_NAME="$GIT_NAME" -e DOCKERHUB_REPO="${IMAGE_NAME}" -e GIT_TOKEN="$GITHUB_TOKEN" -e DOCKERHUB_USER="$DOCKERHUB_USER" -e DOCKERHUB_PASS="$DOCKERHUB_PASS" -e TRIGGER_MAIN_URL="$TRIGGER_MAIN_URL" -e DEPENDENT_DOCKERFILE_URL="" -e GITFLOW_BEHAVIOR="RUN_ON_TAG" eeacms/gitflow'''
}
}
}
}
stage('Update SonarQube Tags: Prod') {
when {
not {
environment name: 'SONARQUBE_TAG', value: ''
}
buildingTag()
}
steps{
node(label: 'docker') {
withSonarQubeEnv('Sonarqube') {
withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GIT_TOKEN')]) {
sh '''docker pull eeacms/gitflow'''
sh '''docker run -i --rm --name="${BUILD_TAG}-sonar" -e GIT_NAME=${GIT_NAME} -e GIT_BRANCH="$BRANCH_NAME" -e GIT_TOKEN="${GIT_TOKEN}" -e SONARQUBE_TAG=${SONARQUBE_TAG} -e SONARQUBE_TOKEN=${SONAR_AUTH_TOKEN} -e SONAR_HOST_URL=${SONAR_HOST_URL} eeacms/gitflow /update_sonarqube_tags_backend.sh'''
}
}
}
}
}
}
post {
always {
cleanWs(cleanWhenAborted: true, cleanWhenFailure: true, cleanWhenNotBuilt: true, cleanWhenSuccess: true, cleanWhenUnstable: true, deleteDirs: true)
}
changed {
script {
def details = """<h1>${env.JOB_NAME} - Build #${env.BUILD_NUMBER} - ${currentBuild.currentResult}</h1>
<p>Check console output at <a href="${env.BUILD_URL}/display/redirect">${env.JOB_BASE_NAME} - #${env.BUILD_NUMBER}</a></p>
"""
emailext(
subject: '$DEFAULT_SUBJECT',
body: details,
attachLog: true,
compressLog: true,
recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'CulpritsRecipientProvider']]
)
}
}
}
}