How to copy all the Jenkins jobs config.xmls with folder names and excluding other jobs related files in single shell command?

1,264 views
Skip to first unread message

RAJENDRA PRASAD

unread,
Jan 11, 2019, 5:03:21 PM1/11/19
to jenkins...@googlegroups.com
Hi all,
I am trying to implement Jenkins jobs backup on existing Jenkins instance and restore on new jenkins server mechanism.

For that I need to copy/backup all the jobs from each jenkins instance .

I am using Linux OS and I need to use shell command for that.

Can anybody help me in with shell command that can only copy job folder name and its config.xml file alone for each job recursively.

Thanks,
Rajendra


Adam von Nieda

unread,
Jan 11, 2019, 7:53:43 PM1/11/19
to jenkins...@googlegroups.com

Here’s a few examples, all run from $JENKINS_HOME/jobs

#!/bin/bash

export JENKINS_HOME=/opt/jenkins

cd $JENKINS_HOME/jobs

#
# Copy directory and config.xml to /tmp
#
find . -name config.xml -exec ls {} \; | while read dir_file
do
   cp --parents $dir_file /tmp
done

#
# tar up directories and config.xml
#
find . -name config.xml -exec ls {} \; | xargs tar cvf backup.tar

#
# Copy directories and config.xml only to remote server
#
find . -name config.xml -exec ls {} \; | xargs tar cf - | ssh user@remotehost "cd /jenkins_home/jobs;tar xvf -"

--
Adam vonNieda




--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAMrg02RZiNdom2ZQBeOjN5iqgBm2jV3L00mU7279KghF17YU4Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages