Created
March 5, 2018 03:17
-
-
Save geerlingguy/c58c53e68bb042a59851202c92cebfb4 to your computer and use it in GitHub Desktop.
Back up a JENKINS_HOME directory to Amazon S3. Meant to be run in a Jenkins job on the server.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: localhost | |
gather_facts: no | |
connection: local | |
vars: | |
aws_region: us-east-1 | |
aws_profile: default | |
s3_bucket_name: jenkins-backup | |
jenkins_home: /var/lib/jenkins | |
tasks: | |
- name: Ensure an S3 bucket exists for the backups. | |
s3_bucket: | |
name: "{{ s3_bucket_name }}" | |
versioning: yes | |
- name: Sync the contents of JENKINS_HOME to S3. | |
command: > | |
aws s3 sync . s3://{{ s3_bucket_name }} | |
--delete | |
--only-show-errors | |
--exclude '.aws/*' | |
--exclude '.ssh/*' | |
--exclude 'workspace/*' | |
--exclude 'workspace' | |
args: | |
chdir: "{{ jenkins_home }}" | |
register: sync_command | |
# See: https://github.com/ansible/ansible/issues/32472 | |
failed_when: False | |
# Allow up to 1 hour for this task to complete, check every 20s. | |
async: 3600 | |
poll: 20 | |
# See: https://github.com/aws/aws-cli/issues/2473 | |
- name: Confirm sync command completed without any critical failures. | |
assert: | |
that: sync_command.rc == 0 or sync_command.rc == 2 | |
- debug: | |
msg: "Backup to s3://{{ s3_bucket_name }} complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Which dsl is this? I believe jenkins dsl is groovy only.