Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy jenkins pipeline project

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?

like image 205
NeoTheThird Avatar asked Dec 08 '25 17:12

NeoTheThird


2 Answers

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.

like image 184
Jehandad Avatar answered Dec 11 '25 10:12

Jehandad


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.

like image 44
tim Avatar answered Dec 11 '25 11:12

tim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!