-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathJenkinsfile
142 lines (128 loc) · 4.59 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
pipeline {
agent any
environment {
// Define environment variables
MLFLOW_TRACKING_URI = "http://35.193.202.32:5000"
NUM_EPOCHS = "1"
EMAIL_ADDRESS = "[email protected]"
MODEL_DIR = "./model_output/distilbert_sentiment_model"
DOCKER_IMAGE = "sentimentanalysis/mlops-sentiment-analysis:latest" // Docker Hub image URL
DOCKER_REGISTRY = "https://index.docker.io/v1/" // Docker Hub registry
GITHUB_CREDENTIALS = credentials('github-token')
}
triggers {
githubPush() // Triggers on any push or PR
}
stages {
stage('Setup Python Environment') {
steps {
script {
// Set up Python virtual environment and install dependencies
sh '''
python3 -m venv .venv
bash -c "source .venv/bin/activate && pip install --upgrade pip && pip install -r model/distilbert/requirements.txt"
'''
}
}
}
stage('Train Model') {
steps {
script {
// Train the model
sh '''
bash -c "source .venv/bin/activate && python3 model/distilbert/train.py"
mkdir -p model_output/distilbert_sentiment_model
cp -r /home/sentimentanalysisreviewproject/model/* model_output/distilbert_sentiment_model/
'''
}
}
}
stage('Validate Model') {
steps {
script {
// Validate the model
sh '''
bash -c "source .venv/bin/activate && python3 model/distilbert/test.py"
'''
}
}
}
stage('Perform Bias Detection') {
steps {
script {
// Perform bias detection
sh '''
bash -c "source .venv/bin/activate && python3 model/distilbert/test_bias.py"
'''
}
}
}
stage('Build Docker Image') {
steps {
script {
// Build the Docker image
echo "Building Docker image..."
sh '''
cp -r model_output/ model/distilbert/
docker build -t $DOCKER_IMAGE -f model/distilbert/Dockerfile model/distilbert
'''
}
}
}
stage('Authenticate to Docker Hub') {
steps {
withCredentials([usernamePassword(credentialsId: 'docker-hub-credentials', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) {
sh """
echo $DOCKER_PASSWORD | docker login --username $DOCKER_USERNAME --password-stdin
"""
}
}
}
stage('Push Docker Image to Docker Hub') {
steps {
script {
// Push the Docker image to Docker Hub
echo "Pushing Docker image to Docker Hub..."
sh '''
docker push $DOCKER_IMAGE
'''
}
}
}
stage('Send Email Notification') {
steps {
script {
// Send email notification (use a plugin or external script)
echo "Email notification to $EMAIL_ADDRESS"
}
}
}
}
post {
success {
script {
// Send email for success
emailext(
subject: "Pipeline Success: ${env.JOB_NAME} [${env.BUILD_NUMBER}]",
body: "The Jenkins pipeline has completed successfully.\n\nJob: ${env.JOB_NAME}\nBuild: ${env.BUILD_NUMBER}\nStatus: SUCCESS",
to: "${EMAIL_ADDRESS}"
)
}
}
failure {
script {
// Send email for failure
emailext(
subject: "Pipeline Failure: ${env.JOB_NAME} [${env.BUILD_NUMBER}]",
body: "The Jenkins pipeline has failed.\n\nJob: ${env.JOB_NAME}\nBuild: ${env.BUILD_NUMBER}\nStatus: FAILURE\nPlease check the logs for details.",
to: "${EMAIL_ADDRESS}"
)
}
}
always {
script {
echo "Pipeline completed!"
}
}
}
}