Skip to content

Commit

Permalink
Merge pull request #39 from fredrikand/master
Browse files Browse the repository at this point in the history
Add support for CloudBees Folder plugin
  • Loading branch information
sue445 committed Apr 8, 2016
2 parents 473730d + 51668e0 commit 810e117
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 5 deletions.
26 changes: 21 additions & 5 deletions jenkins-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,29 @@ if [ "$(ls -A $JENKINS_HOME/nodes/)" ] ; then
cp -R "$JENKINS_HOME/nodes/"* "$ARC_DIR/nodes"
fi

if [ "$(ls -A $JENKINS_HOME/jobs/)" ] ; then
cd "$JENKINS_HOME/jobs/"
ls -1 | while read job_name ; do
mkdir -p "$ARC_DIR/jobs/$job_name/"
find "$JENKINS_HOME/jobs/$job_name/" -maxdepth 1 -name "*.xml" | xargs -I {} cp {} "$ARC_DIR/jobs/$job_name/"
function backup_jobs {
local run_in_path=$1
local rel_depth=${run_in_path#$JENKINS_HOME/jobs/}
cd $run_in_path
find . -maxdepth 1 -type d | while read job_name ; do
[ "$job_name" = "." ] && continue
[ "$job_name" = ".." ] && continue
[ -d $JENKINS_HOME/jobs/$rel_depth/$job_name ] && mkdir -p "$ARC_DIR/jobs/$rel_depth/$job_name/"
find "$JENKINS_HOME/jobs/$rel_depth/$job_name/" -maxdepth 1 -name "*.xml" | xargs -I {} cp {} "$ARC_DIR/jobs/$rel_depth/$job_name/"
if [ -f $JENKINS_HOME/jobs/$rel_depth/$job_name/config.xml ] && [ "$(grep -c "com.cloudbees.hudson.plugins.folder.Folder" $JENKINS_HOME/jobs/$rel_depth/$job_name/config.xml)" -ge 1 ] ; then
#echo "Folder! $JENKINS_HOME/jobs/$rel_depth/$job_name/jobs"
backup_jobs $JENKINS_HOME/jobs/$rel_depth/$job_name/jobs
else
true
#echo "Job! $JENKINS_HOME/jobs/$rel_depth/$job_name"
fi
done
#echo "Done in $(pwd)"
cd -
}

if [ "$(ls -A $JENKINS_HOME/jobs/)" ] ; then
backup_jobs $JENKINS_HOME/jobs/
fi

cd "$TMP_DIR"
Expand Down
32 changes: 32 additions & 0 deletions test/jenkins_home1/jobs/example_folder/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version='1.0' encoding='UTF-8'?>
<com.cloudbees.hudson.plugins.folder.Folder plugin="cloudbees-folder@5.6">
<actions/>
<description></description>
<properties>
<com.cloudbees.hudson.plugins.folder.properties.FolderCredentialsProvider_-FolderCredentialsProperty>
<domainCredentialsMap class="hudson.util.CopyOnWriteMap$Hash">
<entry>
<com.cloudbees.plugins.credentials.domains.Domain plugin="credentials@1.26">
<specifications/>
</com.cloudbees.plugins.credentials.domains.Domain>
<java.util.concurrent.CopyOnWriteArrayList/>
</entry>
</domainCredentialsMap>
</com.cloudbees.hudson.plugins.folder.properties.FolderCredentialsProvider_-FolderCredentialsProperty>
</properties>
<views>
<hudson.model.AllView>
<owner class="com.cloudbees.hudson.plugins.folder.Folder" reference="../../.."/>
<name>All</name>
<filterExecutors>false</filterExecutors>
<filterQueue>false</filterQueue>
<properties class="hudson.model.View$PropertyList"/>
</hudson.model.AllView>
</views>
<viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
<healthMetrics>
<com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric/>
</healthMetrics>
<icon class="com.cloudbees.hudson.plugins.folder.icons.StockFolderIcon"/>
</com.cloudbees.hudson.plugins.folder.Folder>

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version='1.0' encoding='UTF-8'?>
<project>
</project>
32 changes: 32 additions & 0 deletions test/jenkins_home2/jobs/example_folder/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version='1.0' encoding='UTF-8'?>
<com.cloudbees.hudson.plugins.folder.Folder plugin="cloudbees-folder@5.6">
<actions/>
<description></description>
<properties>
<com.cloudbees.hudson.plugins.folder.properties.FolderCredentialsProvider_-FolderCredentialsProperty>
<domainCredentialsMap class="hudson.util.CopyOnWriteMap$Hash">
<entry>
<com.cloudbees.plugins.credentials.domains.Domain plugin="credentials@1.26">
<specifications/>
</com.cloudbees.plugins.credentials.domains.Domain>
<java.util.concurrent.CopyOnWriteArrayList/>
</entry>
</domainCredentialsMap>
</com.cloudbees.hudson.plugins.folder.properties.FolderCredentialsProvider_-FolderCredentialsProperty>
</properties>
<views>
<hudson.model.AllView>
<owner class="com.cloudbees.hudson.plugins.folder.Folder" reference="../../.."/>
<name>All</name>
<filterExecutors>false</filterExecutors>
<filterQueue>false</filterQueue>
<properties class="hudson.model.View$PropertyList"/>
</hudson.model.AllView>
</views>
<viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
<healthMetrics>
<com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric/>
</healthMetrics>
<icon class="com.cloudbees.hudson.plugins.folder.icons.StockFolderIcon"/>
</com.cloudbees.hudson.plugins.folder.Folder>

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version='1.0' encoding='UTF-8'?>
<project>
</project>
8 changes: 8 additions & 0 deletions test/test_jenkins-backup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def expected_files_without_pinned
jenkins-backup/jobs/
jenkins-backup/jobs/example_job/
jenkins-backup/jobs/example_job/config.xml
jenkins-backup/jobs/example_folder/
jenkins-backup/jobs/example_folder/config.xml
jenkins-backup/jobs/example_folder/jobs/example_job_in_folder/
jenkins-backup/jobs/example_folder/jobs/example_job_in_folder/config.xml
jenkins-backup/nodes/
jenkins-backup/nodes/slave/
jenkins-backup/nodes/slave/config.xml
Expand All @@ -55,6 +59,10 @@ def expected_files_with_pinned
jenkins-backup/jobs/
jenkins-backup/jobs/example_job/
jenkins-backup/jobs/example_job/config.xml
jenkins-backup/jobs/example_folder/
jenkins-backup/jobs/example_folder/config.xml
jenkins-backup/jobs/example_folder/jobs/example_job_in_folder/
jenkins-backup/jobs/example_folder/jobs/example_job_in_folder/config.xml
jenkins-backup/nodes/
jenkins-backup/nodes/slave/
jenkins-backup/nodes/slave/config.xml
Expand Down

0 comments on commit 810e117

Please sign in to comment.