Skip to content

Commit dc0c50d

Browse files
committed
Add Jenkinsfile
1 parent 47ea1a5 commit dc0c50d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Jenkinsfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
pipeline {
2+
agent any
3+
4+
environment {
5+
DOCKER_HUB_REPO = "shivammitra/flask-hello-world"
6+
CONTAINER_NAME = "flask-hello-world"
7+
8+
}
9+
10+
stages {
11+
/* We do not need a stage for checkout here since it is done by default when using "Pipeline script from SCM" option. */
12+
13+
stage('Build') {
14+
steps {
15+
echo 'Building..'
16+
sh 'docker image build -t $DOCKER_HUB_REPO:latest .'
17+
}
18+
}
19+
stage('Test') {
20+
steps {
21+
echo 'Testing..'
22+
sh 'docker stop $CONTAINER_NAME || true'
23+
sh 'docker rm $CONTAINER_NAME || true'
24+
sh 'docker run --name $CONTAINER_NAME $DOCKER_HUB_REPO /bin/bash -c "pytest test.py && flake8"'
25+
}
26+
}
27+
stage('Deploy') {
28+
steps {
29+
echo 'Deploying....'
30+
sh 'docker stop $CONTAINER_NAME || true'
31+
sh 'docker rm $CONTAINER_NAME || true'
32+
sh 'docker run -d -p 5000:5000 --name $CONTAINER_NAME $DOCKER_HUB_REPO'
33+
}
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)