forked from bitsensor/elastalert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
58 lines (51 loc) · 1.86 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
pipeline {
agent any
parameters {
booleanParam (name: 'DEPLOY_STAGE', defaultValue: env.BRANCH_NAME == 'master', description: 'deploy without approval')
}
environment {
NAMESPACE = "volcomism"
PROJECT = "elastalert"
GIT_COMMIT_HASH = sh (script: "git log -n 1 --pretty=format:'%h'", returnStdout: true)
DEPLOY_STAGE = "${params.DEPLOY_STAGE}"
SERVICE_NAME = "${env.GIT_URL.replaceAll('^.*/', '').replaceAll('.git$', '')}"
}
stages {
stage('Build') {
steps {
sh "docker build -t ${env.REGISTRY_URL}/${env.NAMESPACE}/${env.PROJECT}:${GIT_COMMIT_HASH} ."
withDockerRegistry([ credentialsId: "registry", url: "https://${env.REGISTRY_URL}" ]) {
sh "docker push ${env.REGISTRY_URL}/${env.NAMESPACE}/${env.PROJECT}:${GIT_COMMIT_HASH}"
}
}
}
stage('Clean') {
steps {
sh "docker rmi -f ${env.REGISTRY_URL}/${env.NAMESPACE}/${env.PROJECT}:${GIT_COMMIT_HASH}"
}
}
stage('Confirm deploy to STAGE ?'){
when {
expression { DEPLOY_STAGE == "false" }
}
steps {
script {
try {
timeout(time: 60, unit: 'SECONDS') {
input "Would you like to deploy elastalert version ${GIT_COMMIT_HASH} to STAGE ?"
DEPLOY_STAGE = true
}
}catch(err){}
}
}
}
stage('Deploy to stage') {
when {
expression { DEPLOY_STAGE != "false" }
}
steps {
deploy serviceName: SERVICE_NAME, version: GIT_COMMIT_HASH, gitBranch: GIT_BRANCH, environment: 'stage'
}
}
}
}