Reputation: 390
I am looking for a way to create a copy of a pipeline project in Jenkins. If i select a normal project, i see an option "Copy Project" in the sidebar, but that is not there in pipeline projects. Is it at all possible to copy pipelines?
Upvotes: 3
Views: 5893
Reputation: 452
This is now possible using the Jenkins UI. When you click "New Item" in the main Jenkins windows, all the way at the bottom you can specify which item you wish to copy. Specify the name of the pipeline there. Jenkins would copy over all the config for you.
Upvotes: 6
Reputation: 407
I do not know of a way to do that in the UI, I am using the Jenkins CLI to do that. I wrote a wrapper for the command line which looks like this:
#!/bin/sh
#file: jenkins_cli.sh
cd $1
if [ -z ${JENKINS_CREDENTIALS+x} -o -z ${JENKINS_SERVER+x} ]
then
JENKINS_SERVER=$(<jenkins_url.txt)
JENKINS_CREDENTIALS=$(<credentials_api.txt)
fi
java -jar jenkins-cli.jar -s $JENKINS_SERVER -auth $JENKINS_CREDENTIALS ${@:2} | dos2unix
since I have subfolders for every Jenkins master I have and those subfolders contain the jenkins_url.txt
and credentials_api.txt
. I then invoke commands like this: ./jenkins_cli <jenkinsxyz> help
.
To save jobs of one Jenkins Master, I created this script:
#!/bin/sh
# save all job configurations locally
#
# parameters:
# directory with credentials_api.txt, jenkins_url.txt and jenkins-cli.jar of
# the jenkins server that will be backuped
cd $1
CLI="./../jenkins_cli.sh"
echo "create backup folder.."
mkdir -p backup
echo "save job list.."
. $CLI . list-jobs | unix2dos.exe > jobs.txt
echo "save job configuration.."
LOOPS=$(wc -l < jobs.txt)
for l in $(seq $LOOPS); do
JOBNAME=$(tail -n+$l jobs.txt | head -n1)
. $CLI . get-job "$JOBNAME" > ./backup/$JOBNAME.xml
echo "saved job nr. $l: $JOBNAME"
done
not the nicest, but it works :) and I am using Git for Windows, thats why I am piping everything to unix2dos.
Upvotes: 1