Created
November 10, 2015 00:33
-
-
Save hishida/c9603817a911ffbdce50 to your computer and use it in GitHub Desktop.
Copy all of Jenkins jobs that is included in certain directory.
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
#!/bin/bash | |
# ex: copy_jenkins_jobs.sh /tmp/jenkinsjobs | |
JENKINS_URL="http://localhost" | |
CONFIG_TMP_XML="config_tmp.xml" | |
DIR=$1 | |
files="$DIR/*" | |
for filepath in $files; do | |
if [ -d $filepath ]; then | |
PROJECT=${filepath##*/} | |
# copy config file | |
cp $DIR/$PROJECT/config.xml $CONFIG_TMP_XML | |
# create a new job | |
curl -f -s -X POST -o /dev/null --data-binary "@$CONFIG_TMP_XML" -H "Content-Type:text/xml" "$JENKINS_URL/createItem?name=${PROJECT}" | |
if [ $? -ne 0 ]; then | |
echo "WARN: $PROJECT already exists on the jenkins server. No action taken." | |
continue | |
fi | |
# disable job | |
curl -s -o /dev/null --data disable "$JENKINS_URL/job/$PROJECT/disable" | |
# remove temporary config file | |
rm $CONFIG_TMP_XML | |
echo "SUCCESS: $PROJECT copied successfully." | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://qiita.com/hishida/items/3c5f1ce84af751bdca74
特定のディレクトリのJenkinsジョブをすべてコピーします。
jobs
以下をコピーしてきたものなどです)JENKINS_URL
はlocalhostを指定していますが、リモートのURLに変更してもできると思います(試していません)