Skip to content

Instantly share code, notes, and snippets.

@bvcelari
Last active April 23, 2020 09:05
Show Gist options
  • Save bvcelari/3979c9b434f6816a8cf10287440b686a to your computer and use it in GitHub Desktop.
Save bvcelari/3979c9b434f6816a8cf10287440b686a to your computer and use it in GitHub Desktop.
#Set Env
JENKINS_SOURCE=http://localhost:9999
JENKINS_DESTINATION=http://localhost:8888
SOURCE_FOLDER=Fancy_SourceFolder
DESTINATION_FOLDER=Fancy_DestinationFolder
TEMP_FOLDER=Store_tmp_folder
#Retrieve the cli
wget $JENKINS_SOURCE/jnlpJars/jenkins-cli.jar
chmod +x ./jenkins-cli.jar
#Create a folder to store the jobs information.
mkdir Jobs_for_${SOURCE_FOLDER}
#Retrieve the list of Jobs and Folders in the destionation folder:
java -jar ./jenkins-cli.jar -s ${JENKINS_SOURCE} -http -auth admin:admin list-jobs ${SOURCE_FOLDER} 2> /dev/null > Jobs_for_${TEMP_FOLDER}/List_Jobs
#Retrieve each one of the jobs inside the folder
for file in $(cat Jobs_for_${TEMP_FOLDER}/List_Jobs)
do
java -jar ./jenkins-cli.jar -s ${JENKINS_SOURCE} -http -auth admin:admin get-job ${SOURCE_FOLDER}/${file} 2> /dev/null > Jobs_for_${TEMP_FOLDER}/Job_$file
done
#Create the jobs on the new instance
for job_name in $(cat Jobs_for_${TEMP_FOLDER}/List_Jobs)
do
java -jar ./jenkins-cli.jar -s ${JENKINS_DESTINATION} -http -auth admin:admin create-job ${DESTINATION_FOLDER}/${job_name} 2> /dev/null < Jobs_for_${TEMP_FOLDER}/Job_${job_name}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment