-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
executable file
·123 lines (115 loc) · 2.82 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
pipeline {
agent any
//agent { docker { image "maven:3.6.3" } }
triggers {
GenericTrigger(
genericVariables: [
[key: 'email', value: '$.actor.emailAddress'],
[key: 'event', value: '$.eventKey'],
[key: 'ssh_link', value: '$.pullRequest.toRef.repository.links.clone[0].href'],
],
causeString: 'Triggered on ${event}',
token: '11b8c3b49dbe7c8a5ff593ada2a52f17ef',
tokenCredentialId: 'mrunyon',
printPostContent: true,
silentResponse: false,
)
}
environment {
ADMIN_EMAIL = "[email protected]"
dockerHome = tool "myDocker"
mavenHome = tool "myMaven"
PATH = "$dockerHome/bin:$mavenHome/bin:$PATH"
CHECKOUT_PATH = "~ci/repos/my_repo"
CREDENTIALS = "my_scm_credentials"
LINT_SCRIPT_PATH = "/path/to/linter/"
TEST_SCRIPT_PATH = "/usr/bin/python3/"
}
stages {
stage('Checkout'){
steps {
sh "docker version"
echo "Checkout"
echo "PATH - $env.PATH"
echo "BUILD_NUMBER - $env.BUILD_NUMBER"
echo "BUILD_ID - $env.BUILD_ID"
echo "JOB_NAME - $env.JOB_NAME"
echo "BUILD_TAG - $env.BUILD_TAG"
checkout(
[$class: 'GitSCM',
branches: [[name: '*/master']],
extensions: [[
$class: 'RelativeTargetDirectory',
relativeTargetDir: WORKSPACE
],
[
$class: 'SubmoduleOption',
disableSubmodules: false,
parentCredentials: true,
recursiveSubmodules: true,
reference: '',
trackingSubmodules: false
]],
userRemoteConfigs: [[credentialsId: CREDENTIALS,
url: ${ssh_link}]]
]
)
}
}
stage('Test'){
steps {
sh "${TEST_SCRIPT_PATH}python -m pytest ${WORKSPACE}\\python\\tests\\ "
}
}
stage('Lint'){
steps {
sh "${LINT_SCRIPT_PATH} | ${WORKSPACE}\\lint_results.txt"
}
}
stage('Package'){
steps {
sh "mvn package -D skipTests"
}
}
stage('Build Docker Image'){
steps {
//"docker build -t m4ttl33t/currency-exchange-devops:$env.BUILD_TAG"
script {
dockerImage = docker.build("m4ttl33t/currency-exchange-devops:${env.BUILD_TAG}")
}
}
}
stage('Push Docker Image'){
steps {
script {
docker.withRegistry('', 'dockerhub'){
dockerImage.push();
dockerImage.push('latest');
}
}
}
}
}
post {
always {
echo "I'm awesome. I run always."
}
success {
mail bcc: ADMIN_EMAIL,
body: "The build ${env.BUILD_ID} was successful. "
from: 'Your friendly neighborhood Spiderman',
replyTo: '',
subject: "SUCCESS: ${env.BUILD_TAG}",
to: email
}
failure {
mail bcc: ADMIN_EMAIL,
body: "The build ${env.BUILD_ID} was not successful. "
from: 'Your friendly neighborhood Spiderman',
replyTo: '',
subject: "FAILURE: ${env.BUILD_TAG}",
to: email
}
}
// changed - when build-to-build status changes, e.g., fail-to-success
}