-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkinsFilePyhonDocker
118 lines (113 loc) · 3 KB
/
jenkinsFilePyhonDocker
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
pipeline {
/*
* Run everything on an existing agent configured with a label 'docker'.
* This agent will need docker, git and a jdk installed at a minimum.
* https://stackoverflow.com/questions/26472586/upgrade-docker-on-centos-7
* install latest docker
* start docker demon
* "chmod 666 /var/run/docker.sock"
*/
/*
* https://xerosecurity.com/wordpress/documentation/
*/
agent {
node {
label 'master'
}
}
// using the Timestamper plugin we can add timestamps to the console log
options {
timestamps()
disableConcurrentBuilds()
}
environment {
//Use Pipeline Utility Steps plugin to read information from pom.xml into env variables
IMAGE = 'sn1per'
VERSION = '1'
//Use Pipeline Utility Steps for python env variables
//IMAGE = 'simplejavaproject'
//VERSION = readMavenPom().getVersion()
//VERSION = '2.2.2'
//registry = "myreg/docker-test"
//imagename = "cloudties/dockerimage"
//registryCredential = 'cloudties123$'
//dockerImage = ''
}
stages {
stage('Clone Python repository') {
steps {
script {
checkout(
[
$class: 'GitSCM',
branches: [
[name: '*/master']
],
doGenerateSubmoduleConfigurations: false,
extensions: [],
submoduleCfg: [],
userRemoteConfigs: [
[
credentialsId: 'cloudties',
url: 'https://github.com/1N3/Sn1per.git']
]
])
}}
}
stage('Python build') {
agent {
docker {
/*
* Reuse the workspace on the agent defined at top-level of
* Pipeline but run inside a container.
*/
image 'kalilinux/kali-rolling'
reuseNode true
}
}
when {
expression { false == true }
}
steps {
script {
sh '''
set -eux pipefail
sh 'pip3 install -r requirements.txt'
'''
}
}
}
stage('Build docker image') {
steps {
script {
sh '''
docker version
docker build -t ${IMAGE} .
docker tag ${IMAGE} ${IMAGE}:${VERSION}
docker run -d ${IMAGE}:${VERSION} /bin/bash
#docker push ${IMAGE}:${VERSION}
'''
}
}
}
stage('Run Python app') {
agent {
label 'master'
}
steps {
script {
sh "docker exec -u 0 \$(docker ps | grep sn1per | awk '{print \$1}') /bin/sh -c 'sniper -t https://www.cloudties.in'"
}
}
}
stage('Remove Unused docker image') {
steps {
script {
//sh "docker rmi ${IMAGE}:${VERSION}"
//sh "docker rmi ${IMAGE}:latest"
sh "docker image ls"
}
}
}
}
}