-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathJenkinsfile
93 lines (93 loc) · 3.95 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
def ORG = "mayadataio"
def REPO = "cstorpoolauto"
def TAG = ""
pipeline {
agent any
stages {
stage('Build Image') {
steps {
script {
GIT_SHA = sh(
returnStdout: true,
script: "git log -n 1 --pretty=format:'%h'"
).trim()
echo "Building docker image(s)"
sh "docker build -t ${ORG}/${REPO}:ci-${GIT_SHA} ."
}
}
}
stage('Dependencies'){
when { expression { env.CHANGE_ID == null } }
steps {
script {
sh """
git clone [email protected]:mayadata-io/maya-io-release.git
"""
if (env.BRANCH_NAME == 'master') {
TAG = sh (returnStdout: true,script: "./maya-io-release/utils/version_override ${REPO} ${env.BRANCH_NAME}").trim()
echo "$TAG"
} else {
TAG = sh (returnStdout: true,script: "./maya-io-release/utils/tag_fetch.sh ${REPO} ${env.BRANCH_NAME}").trim()
echo "$TAG"
}
}
}
}
stage('Push Image') {
steps {
script {
withCredentials([usernamePassword( credentialsId: 'docke_cred', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
if(env.BRANCH_NAME == TAG){
echo "Pushing the image with the tag..."
sh "docker login -u${USERNAME} -p${PASSWORD} "
sh "docker tag ${ORG}/${REPO}:ci-${GIT_SHA} ${ORG}/${REPO}:${TAG} && docker push ${ORG}/${REPO}:${TAG}"
} else if (env.BRANCH_NAME == 'master') {
withCredentials([usernamePassword( credentialsId: 'dd46bd83-0e93-492b-bc43-fcb671b135c3', usernameVariable: 'user', passwordVariable: 'pass')]) {
sh """
git tag -fa "${TAG}" -m "Release of ${TAG}"
"""
sh "git tag -l"
sh """
git push https://${user}:${pass}@github.com/mayadata-io/${REPO}.git --tag
"""
}
} else {
echo "WARNING: Not pushing Image"
}
}
}
}
}
}
post {
always {
echo 'This will always run'
deleteDir()
}
success {
echo 'This will run only if successful'
slackSend channel: '#jenkins-builds',
color: 'good',
message: "The pipeline ${currentBuild.fullDisplayName} completed successfully :dance: :thumbsup: "
}
failure {
echo 'This will run only if failed'
slackSend channel: '#jenkins-builds',
color: 'RED',
message: "The pipeline ${currentBuild.fullDisplayName} failed. :scream_cat: :japanese_goblin: "
}
unstable {
echo 'This will run only if the run was marked as unstable'
slackSend channel: '#jenkins-builds',
color: 'good',
message: "The pipeline ${currentBuild.fullDisplayName} is unstable :scream_cat: :japanese_goblin: "
}
changed {
/* slackSend channel: '#jenkins-builds',
color: 'good',
message: "Build ${currentBuild.fullDisplayName} is now stable :dance: :thumbsup: "
echo 'This will run only if the state of the Pipeline has changed'
*/ echo 'For example, if the Pipeline was previously failing but is now successful'
}
}
}