forked from dorondollev/PolyBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbotDeploy.Jenkinsfile
More file actions
43 lines (42 loc) · 1.64 KB
/
botDeploy.Jenkinsfile
File metadata and controls
43 lines (42 loc) · 1.64 KB
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
pipeline {
agent any
parameters {
string(name: 'BOT_IMAGE_NAME')
}
stages {
stage("Install Ansible") {
steps {
sh 'python3 -m pip install ansible'
sh '/var/lib/jenkins/.local/bin/ansible-galaxy collection install community.general'
}
}
stage("Generate Ansible Inventory") {
environment {
BOT_EC2_APP_TAG = "daniel-reuven-polybot-deployed"
BOT_EC2_REGION = "eu-central-1"
}
steps {
sh 'aws ec2 describe-instances --region $BOT_EC2_REGION --filters "Name=tag:App,Values=$BOT_EC2_APP_TAG" --query "Reservations[].Instances[]" > hosts.json'
sh 'python3 prepare_ansible_inv.py'
sh '''
echo "Inventory generated"
cat hosts
'''
}
}
stage('Ansible Bot Deploy') {
environment {
ANSIBLE_HOST_KEY_CHECKING = 'False'
REGISTRY_URL = "352708296901.dkr.ecr.eu-central-1.amazonaws.com"
REGISTRY_REGION = 'eu-central-1'
}
steps {
withCredentials([sshUserPrivateKey(credentialsId: 'jenkins-ec2-user', usernameVariable: 'ssh_user', keyFileVariable: 'privatekey')]) {
sh '''
/var/lib/jenkins/.local/bin/ansible-playbook botDeploy.yaml --extra-vars "registry_region=$REGISTRY_REGION registry_url=$REGISTRY_URL bot_image=$BOT_IMAGE_NAME" --user=${ssh_user} -i hosts --private-key ${privatekey}
'''
}
}
}
}
}