This repository has been archived by the owner on Aug 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Jenkinsfile.deploy
66 lines (61 loc) · 1.85 KB
/
Jenkinsfile.deploy
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
def notify(message, color='good') {
if (notify_slack.toBoolean()) {
slackSend message: message,
color: color,
failOnError: true
}
}
pipeline {
agent {
label 'app-deploys'
}
stages {
stage('Notify Slack') {
steps {
notify """Deploying `${application}` to `${environment}`.
|${currentBuild.rawBuild.getCauses()[0].getShortDescription()}
|${currentBuild.getAbsoluteUrl()}""".stripMargin()
}
}
stage('Checkout Code') {
steps {
checkout poll: false,
changelog: false,
scm: [$class: 'GitSCM', branches: [[name: '*/master']],
extensions: [[$class: 'SubmoduleOption', recursiveSubmodules: true]],
userRemoteConfigs: [[url: '[email protected]:department-of-veterans-affairs/devops.git']]]
}
}
stage('Create virtualenv') {
steps {
dir('ansible') {
sh 'virtualenv venv'
sh 'venv/bin/pip install -r requirements.txt'
}
}
}
stage('Run Ansible deploy') {
steps {
dir('ansible') {
sh "bash -c 'source venv/bin/activate && ansible-playbook " +
"-e env=${environment} " +
"-e app_name=${application} " +
"-e force_ami=${force_ami} " +
"-e git_version=${branch.split('/')[-1]} " +
"-i inventory " +
"aws-deploy-app.yml'"
}
}
}
}
post {
success {
notify """Successfully deployed `${application}` to `${environment}`.
|Took ${currentBuild.rawBuild.getDurationString()}""".stripMargin()
}
failure {
notify """Failed to deploy `${application}` to `${environment}`!
|${currentBuild.getAbsoluteUrl()}console""".stripMargin(), 'danger'
}
}
}