forked from LordEaster/share-bill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
84 lines (84 loc) · 3.12 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
pipeline {
agent any
environment {
GIT_URL = 'https://github.com/BSO-Space/share-bill'
SLACK_CHANNEL = '#jenkins-notifications'
}
parameters {
string(name: 'BRANCH_NAME', defaultValue: 'main', description: 'Branch name for the build')
string(name: 'DOCKER_TAG', defaultValue: 'latest', description: 'Docker image tag')
}
stages {
stage("Checkout & Pulling") {
steps {
script {
git branch: "${params.BRANCH_NAME}", url: "${GIT_URL}"
if ("${params.BRANCH_NAME}" != "main") {
error("This pipeline only runs on the main branch. Current branch: ${params.BRANCH_NAME}")
}
sh "git pull origin ${params.BRANCH_NAME}"
}
}
post {
always {
echo "In Processing"
}
success {
echo "Successful"
}
failure {
echo "Failed"
}
}
}
stage("Code analysis") {
steps {
withCredentials([string(credentialsId: 'share-bill', variable: 'SONAR_TOKEN')]) {
sh '''
npm install sonar-scanner
npx sonar-scanner \
-Dsonar.projectKey=share-bill \
-Dsonar.host.url=http://sonarqube-dso-demo:9000 \
-Dsonar.login=$SONAR_TOKEN
'''
}
}
}
stage("Docker deployment") {
steps {
sh 'docker-compose -p share-bill -f docker-compose.prod.yml build --no-cache'
sh 'docker-compose -p share-bill -f docker-compose.prod.yml up -d'
}
}
}
post {
always {
echo "Pipeline finished"
slackSend channel: "${SLACK_CHANNEL}", color: '#00FF00', message: """
*Pipeline Finished*: ${env.JOB_NAME} [#${env.BUILD_NUMBER}]
*Status*: ${currentBuild.currentResult}
*Branch*: ${params.BRANCH_NAME}
*Last Commit By*: ${env.LAST_COMMIT_AUTHOR}
*Commit Message*: ${env.LAST_COMMIT_MESSAGE}
"""
}
success {
echo "Pipeline success"
slackSend channel: "${SLACK_CHANNEL}", color: '#36A64F', message: """
*Pipeline Success*: ${env.JOB_NAME} [#${env.BUILD_NUMBER}]
*Branch*: ${params.BRANCH_NAME}
*Last Commit By*: ${env.LAST_COMMIT_AUTHOR}
*Commit Message*: ${env.LAST_COMMIT_MESSAGE}
"""
}
failure {
echo "Pipeline error"
slackSend channel: "${SLACK_CHANNEL}", color: '#FF0000', message: """
*Pipeline Failed*: ${env.JOB_NAME} [#${env.BUILD_NUMBER}]
*Branch*: ${params.BRANCH_NAME}
*Last Commit By*: ${env.LAST_COMMIT_AUTHOR}
*Commit Message*: ${env.LAST_COMMIT_MESSAGE}
"""
}
}
}