-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
93 lines (90 loc) · 3.74 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
pipeline {
agent any
environment {
AWS_DEFAULT_REGION = 'ap-south-1'
}
stages{
stage('Checking python version'){
steps{
sh 'python3 -V'
}
}
stage('Cloning the repo'){
steps{
script{
try {
checkout scmGit(branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[url: 'https://github.com/abhiunix/aws_waf_slack_integration']])
sh 'echo clone completed'
} catch (Exception e) {
echo "Error: ${e.message}"
currentBuild.result = 'FAILURE'
}
}
}
stage('converting the repo to prod') {
steps{
script{
withCredentials([
string(credentialsId: 'YourUserName_id', variable: 'YourUserName'),
string(credentialsId: 'YourAWSprofile_id', variable: 'YourAWSprofile'),
string(credentialsId: 'YourTeamDomain_id', variable: 'YourTeamDomain'),
string(credentialsId: 'YourChannelName_id', variable: 'YourChannelName')
]) {
sh """
SEARCH_DIR="\${WORKSPACE}"
find "\$SEARCH_DIR" -type f \\( -name "*.py" -o -name "*.txt" \\) | while read -r FILE; do
sed -i '' "s/YourUserName/\${YourUserName}/g" "\$FILE"
sed -i '' "s/YourAWSprofile/\${YourAWSprofile}/g" "\$FILE"
sed -i '' "s/YourTeamDomain/\${YourTeamDomain}/g" "\$FILE"
sed -i '' "s/YourChannelName/\${YourChannelName}/g" "\$FILE"
echo "The file \$FILE has been updated."
done
echo "Conversion to prod completed."
"""
}
}
}
}
stage('building the docker image'){
steps{
script{
sh '/opt/homebrew/bin/docker build -t abhiunix/aws_waf_slack_integration:v1 .'
sh 'echo "docker build successful"'
}
}
}
stage('Stoping previous container'){
steps{
script{
sh """
/opt/homebrew/bin/docker ps | grep 8002 | awk -F' ' '{print \$1}' | xargs /opt/homebrew/bin/docker stop
"""
}
}
}
stage('Push to docker hub'){
steps{
script{
withCredentials([string(credentialsId: 'dockerhub_pwd', variable: 'docker_pwd')]) {
sh '/opt/homebrew/bin/docker login -u abhiunix -p ${docker_pwd}'
}
sh '/opt/homebrew/bin/docker push abhiunix/aws_waf_slack_integration:v1'
}
}
}
stage('Run the container') {
steps {
script {
sh """
IMAGE_ID=\$(/opt/homebrew/bin/docker images | grep 'abhiunix/aws_waf_slack_integration' | awk -F' ' '{print \$3}' | head -n 1)
if [ ! -z "\$IMAGE_ID" ]; then
/opt/homebrew/bin/docker run -dt -p 8002:8002 -v /Users/abhijeetsingh/Downloads/scripts/.aws:/root/.aws:ro -e AWS_DEFAULT_REGION=ap-south-1 -e AWS_PROFILE=curefit-security-devs \$IMAGE_ID
else
echo "Image not found!"
fi
"""
}
}
}
}
}