This repository has been archived by the owner on Sep 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
84 lines (76 loc) · 2.72 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 { label 'SagaLabs1' }
parameters {
string(name: 'ENV', defaultValue: 'development', description: 'Environment to deploy')
}
environment {
BRANCH_NAME = "${env.BRANCH_NAME}"
}
options {
skipDefaultCheckout() // Disable the declarative 'Checkout SCM' step
}
stages {
stage('Clean Workspace') {
steps {
cleanWs()
}
}
stage('Check Docker Installation') {
steps {
script {
// Check if Docker is installed
def dockerInstalled = sh(script: 'which docker', returnStatus: true) == 0
// If Docker is not installed, then echo a message
if (!dockerInstalled) {
error('Docker is not installed. Please install Docker before running this pipeline.')
} else {
echo 'Docker is installed, proceeding with the pipeline.'
}
}
}
}
stage('Check Docker Compose Installation') {
steps {
script {
// Check if Docker Compose is installed
def dockerComposeInstalled = sh(script: 'which docker-compose', returnStatus: true) == 0
// If Docker Compose is not installed, then echo a message
if (!dockerComposeInstalled) {
error('Docker Compose is not installed. Please install Docker Compose before running this pipeline.')
} else {
echo 'Docker Compose is installed, proceeding with the pipeline.'
}
}
}
}
stage('Clone GitHub repository') {
steps {
sh "git clone --branch ${params.ENV} https://github.com/cvpl-fdca/SagaLabs-webmanager.git ."
}
}
stage('Get .env file') {
steps {
withCredentials([file(credentialsId: 'env-file-webmanager', variable: 'ENV_FILE_PATH')]) {
sh '''
cp "${ENV_FILE_PATH}" .env
chmod u+w .env
'''
}
}
}
stage('Populate .env file') {
steps {
script {
def branchName = params.ENV
sh 'echo "" >> .env'
sh "echo \"BRANCH_NAME=${branchName}\" >> .env"
}
}
}
stage('Docker Compose Build and Run') {
steps {
sh 'docker-compose up --force-recreate --build -d'
}
}
}
}