說明:從一個Jenkins服務器A將現有job遷移到另外一個Jenkins服務器B。
方法:
You can copy or move build jobs between instances of projects simply enough by copying or moving the
build job directories to the new Jenkins instance.
具體步驟如下:
1、首先確認Jenkins的job存放目錄。
以管理員賬號登錄Jenkins,點擊“系統管理/系統設置”,確認jenkins工作目錄。
本例中
Jenkins A的工作目錄為
/home/.jenkins,
Jenkins B的工作目錄為
/root/.jenkins。
2、接下來,遷移jobs目錄。
登錄Jenkins A服務器,進入工作目錄,
壓縮jobs目錄,並復制到B:
cd /home/.jenkins
tar -czvf jobs.tar.gz jobs
scp -f jobs.tar root@BIP:/root/.jenkins/
3、接着,在B上解壓jobs.tar到jobs目錄,並重啟Jenkins服務器B。注意:重啟不是必須的。
1)通過重啟hudson來加載新遷移的job:
cd /root/.jenkins
tar -zxvf jobs.tar
本例通過重啟tomcat服務來重啟Jenkins,其他通過jar運行Jenkins的重啟進程即可。
cd /opt/tomcat/tomcat7/bin/
./shutdown.sh
./startup.sh
2)不需要重啟:
just go to the Manage Jenkins screen and click on Reload Configuration From
Disk. This will load the new jobs and make them immediately visible on the Jenkins dashboard.

點擊上述紅框中的“讀取設置”按鈕后,顯示如下信息:

4、最后,驗證B上是否已經加載了遷移進來的新job,同時需要對job進行配置。
1)登錄到Jenkins B后,發現A上的jobs已經正確遷移進來。如下:

5、注意事項
1)修改job的配置:
由於之前job設置是在Jenkins A的某個節點上執行,所以如果想讓它在Jenkins B的某個節點上執行,則需要檢查job的配置“
Restrict where this project can be run
”,設置job運行的節點。

2)插件:如果Jenkins A上安裝了插件,而B沒有,則遷移過來的任務可能也需要安裝A上的插件。
There are a few gotchas, however. If you are migrating your jobs to a brand new Jenkins configuration,
remember to install, or migrate, the plugins from your original server. The plugins can be found in
the
plugins directory, so you can simply copy everything from this directory to the corresponding
directory in your new instance.