1. 程式人生 > 實用技巧 >Jenkins更換國內外掛源以及Jenkins更新(Jenkins部署在Docker中)

Jenkins更換國內外掛源以及Jenkins更新(Jenkins部署在Docker中)

一、Jenkins更換國內外掛源

  • 在jenkins頁面中點選"Manage Jenkins"--->"Manage Plugins"--->"Advanced"

    將圖中URL改為:

    https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
    

    點選提交。

  • 為確保配置生效,需要更改配置檔案:

    進入到jenkins工作目錄當中,我的應用都部署在docker當中,並且做了資料對映,因此直接在宿主機當中進行修改。

    [root@node03 docker-jenkins]# cd data/updates/
    [root@node03 updates]# ll
    total 2300
    -rw-r--r--. 1 1000 1000 2016327 Nov 12 17:02 default.json
    -rw-r--r--. 1 1000 1000   33070 Nov 12 17:10 hudson.plugins.gradle.GradleInstaller
    -rw-r--r--. 1 1000 1000    5116 Nov 12 17:10 hudson.tasks.Ant.AntInstaller
    -rw-r--r--. 1 1000 1000    5350 Nov 12 17:02 hudson.tasks.Maven.MavenInstaller
    -rw-r--r--. 1 1000 1000  279724 Nov 12 17:10 hudson.tools.JDKInstaller
    
  • 使用sed命令修改default.json檔案

    sed -i 's#https://updates.jenkins.io/download#https://mirrors.tuna.tsinghua.edu.cn/jenkins#g' default.json && sed -i 's#http://www.google.com#https://www.baidu.com#g' default.json
    
  • 更改之後重啟Jenkins

二、Docker安裝的Jenkins進行更新

  • 進入jenkins時提示有新版本,點選下載到本地,然後通過ftp軟體將war包上傳至Jenkins工作目錄當中

    [root@node03 data]# ls
    config.xml                      jenkins.install.InstallUtil.lastExecVersion     jobs              queue.xml.bak             userContent
    copy_reference_file.log         jenkins.install.UpgradeWizard.state             logs              secret.key                users
    hudson.model.UpdateCenter.xml   jenkins.model.JenkinsLocationConfiguration.xml  nodeMonitors.xml  secret.key.not-so-secret  war
    hudson.plugins.git.GitTool.xml  jenkins.telemetry.Correlator.xml                nodes             secrets                   workflow-libs
    identity.key.enc                jenkins.war                                     plugins           updates
    
  • 以root使用者進入到Jenkins容器當中

    [root@node03 data]# docker exec -it -u root 8286 /bin/bash
    root@8286c620ab88:/# whereis jenkins
    #找到jenkins的安裝目錄
    jenkins: /usr/local/bin/jenkins.sh /usr/share/jenkins
    root@8286c620ab88:/# cd /usr/share/jenkins/
    root@8286c620ab88:/usr/share/jenkins# ls
    jenkins.war  ref
    #備份jenkins.war檔案
    root@8286c620ab88:/usr/share/jenkins# cp jenkins.war jenkins.war.bakup
    #將剛才上傳的jenkins.war檔案覆蓋掉
    root@8286c620ab88:/usr/share/jenkins# cp /var/jenkins_home/jenkins.war /usr/share/jenkins/
    
  • 重啟Jenkins

    可以看到,Jenkins由剛才的2.249.2升級到2.266