forked from ArturoI/warp-engine
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
142 lines (133 loc) · 5.19 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
pipeline {
agent {
node {
label 'ansible-ci'
}
}
parameters {
choice(
name: 'deploy',
choices: ['release','documentation'],
description: 'Choice option to Deploy'
)
}
environment {
BUILD_VERSION = sh(script: 'date +%Y.%m.%d', , returnStdout: true).trim()
COMMIT_VERSION = sh(script: 'git rev-parse --short HEAD', , returnStdout: true).trim()
}
stages {
stage('Build Release') {
when {
branch 'master'
expression { params.deploy == 'release' }
}
steps {
sh "cat release/commit.sh.template | sed -e 's/COMMIT_VERSION/${COMMIT_VERSION}/' > .warp/lib/commit.sh"
sh "cat release/version.sh.template | sed -e 's/BUILD_VERSION/${BUILD_VERSION}/' > .warp/lib/version.sh"
sh "tar cJf warparchive.tar.xz .warp/."
sh "cat warp > dist/warp"
sh "cat warparchive.tar.xz >> dist/warp"
sh "chmod +x dist/warp"
sh "cp dist/warp dist/warp_${BUILD_VERSION}"
}
}
stage('Generate Tag') {
when {
branch 'master'
expression { params.deploy == 'release' }
}
steps {
script {
sshagent (credentials: ['BITBUCKET']) {
sh """
ssh-keyscan -H bitbucket.org >> ~/.ssh/known_hosts
git config user.email "${env.EMAIL_DEVOPS}"
git config user.name "Jenkins"
git tag ${BUILD_VERSION}
git push origin ${BUILD_VERSION}
"""
}
}
}
}
stage('Deploy') {
when {
branch 'master'
expression { params.deploy == 'release' }
}
steps {
script {
withCredentials([
[
$class: 'AmazonWebServicesCredentialsBinding',
credentialsId: 'AWS_SUMMA_CREDENTIALS',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'
]
])
{
sh "aws s3 cp ./dist/warp s3://ct.summasolutions.net/warp-engine/warp"
sh "aws s3 cp ./dist/warp s3://ct.summasolutions.net/warp-engine/old/warp_${BUILD_VERSION}"
}
}
}
post {
success {
echo "Success!"
slackSend (
channel: "${env.CHANNEL_SLACK_WARP}",
color: "good",
message: ":docker: *NEW VERSION WARP ${BUILD_VERSION}* :docker: \n Documentation: https://summasolutions.github.io/warp-engine/ \n More info at: https://github.com/SummaSolutions/warp-engine/blob/master/CHANGES.md"
)
}
failure {
echo "Failure!"
slackSend (
channel: "${env.CHANNEL_SLACK_WARP}",
color: "danger",
message: "*${currentBuild.currentResult}:* Job ${env.JOB_NAME} build ${env.BUILD_NUMBER}\n More info at: ${env.BUILD_URL}"
)
}
}
}
stage('Deploy to Github') {
echo "deploy to github"
// For SSH private key authentication, try the sshagent step from the SSH Agent plugin.
//sshagent (credentials: ['GITHUB']) {
// sh('ssh-keyscan -H github.com >> ~/.ssh/known_hosts')
// sh('git push origin master')
// sh("git push origin ${BUILD_VERSION}")
//}
}
stage('Documentation') {
when {
branch 'master'
expression { params.deploy == 'documentation' }
}
steps {
sh "python -m pip install -r requirements.txt"
sh "mkdocs build --site-dir docs"
script {
sshagent (credentials: ['BITBUCKET']) {
sh """
ssh-keyscan -H bitbucket.org >> ~/.ssh/known_hosts
git config user.email "${env.EMAIL_DEVOPS}"
git config user.name "Jenkins"
git add docs wiki_docs
git commit -m "build documentation ${BUILD_VERSION}_${COMMIT_VERSION}"
git push origin master
"""
}
}
}
}
}
post {
always {
dir("${WORKSPACE}") {
deleteDir()
}
echo "delete temporary workspace"
}
}
}