-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
63 lines (60 loc) · 2.11 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
def email = "morbargig"
def repo = "https://github.com/morbargig/echo-app"
def branch = "${BRANCH_NAME}"
pipeline {
agent any
stages {
stage('pull') {
steps {
script {
if ( !["dev","master","stg"].contains("${branch}")) {
echo "${branch}"
echo "not knowed branch"
}
commit=sh (script: "git log -1 | tail -1", returnStdout: true).trim()
}
}
}
stage('build') {
steps {
script{
tag="${branch}-${commit}"
if ( "${branch}" == "master" ){
tag="${commit}"
}
sh " docker build -t ${tag} ."
}
}
}
stage('deply') {
steps {
script{
withCredentials([usernamePassword( credentialsId: 'docker-hub-credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
echo "${USERNAME} ${PASSWORD}"
sh "docker login -u ${USERNAME} -p ${PASSWORD}"
sh " docker tag ${tag} morbargig/echo-app:${tag}"
sh " docker push morbargig/echo-app:${tag}"
}
}
}
}
}
post {
success{
script{
// mail me success
mail to: "morbargi@gamil.com"
subject: "${env.JOB_NAME} - (${env.BUILD_NUMBER}) Successfuly",
body: "APP building SUCCESSFUL!, see console output at ${env.BUILD_URL} to view the results"
}
}
failure{
script{
// mail me failure
mail to: "{email}"
subject: "${env.JOB_NAME} - (${env.BUILD_NUMBER}) FAILED",
body: "APP building FAIL!, Check console output at ${env.BUILD_URL} to view the results"
}
}
}
}