Repository navigation
Expand file tree
/
Copy pathJenkinsFile
More file actions
78 lines (69 loc) · 2.06 KB
/
Copy pathJenkinsFile
File metadata and controls
78 lines (69 loc) · 2.06 KB
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
pipeline {
agent any
environment {
DOCKER_IMAGE = "branson404/project-django"
DOCKER_TAG = "${DOCKER_IMAGE}:${BUILD_NUMBER}"
}
stages {
stage('Git checkout') {
steps {
git branch: 'main', url: 'https://github.com/branson404/project-django'
}
}
stage('SonarQube Analysis') {
steps {
script {
def sonarScanner = tool 'SonarScanner'
withSonarQubeEnv('sonarqube-credentials') {
sh "${sonarScanner}/bin/sonar-scanner -Dsonar.projectKey=project-django -X"
}
}
}
}
stage('Docker login') {
steps {
withCredentials([usernamePassword(credentialsId: 'dockerhub', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
sh 'echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin'
}
}
}
stage('Build Docker image') {
steps {
sh 'docker build -t $DOCKER_IMAGE .'
sh 'docker tag $DOCKER_IMAGE $DOCKER_TAG'
}
}
stage('Docker push') {
steps {
sh 'docker push $DOCKER_IMAGE'
sh 'docker push $DOCKER_TAG'
}
}
stage('Docker logout') {
steps {
sh 'docker logout'
}
}
stage('Run Docker Container') {
steps {
sh '''
if [ "$(docker ps -aq -f name=main_line)" ]; then
docker rm -f main_line
fi
'''
sh 'docker run -d -p 8000:8000 --name main_line $DOCKER_IMAGE'
}
}
}
post {
always {
echo 'Pipeline execution completed.'
}
success {
echo 'Build and deployment successful.'
}
failure {
echo 'Build failed.'
}
}
}