Jenkins on Windows 心得分享 (07):如何手動更新 Jenkins 伺服器所有外掛 | The Will Will Web

The Will Will Web

記載著 Will 在網路世界的學習心得與技術分享

Jenkins on Windows 心得分享 (07):如何手動更新 Jenkins 伺服器所有外掛

當你已經安裝一大堆 Jenkins Plugins,想要全部自動更新,但是又連不到 Jenkins 指向的 Mirror Sites 的話,想必就只能手動更新了。本篇文章延續 Jenkins on Windows 心得分享 (06):如何指定 Mirror 鏡像網站下載外掛 的內容,特別補充如何手動更新 Jenkins 伺服器所有外掛(Plugins)。

取得目前 Jenkins 所有 Plugins 清單

  1. 開啟 Manage Jenkins > Script Console 輸入命令

    Manage Jenkins > Script Console

  2. 輸入以下 Groovy script 命令,並按下 Run 按鈕執行

    Jenkins.instance.pluginManager.plugins.each{ plugin -> print ("${plugin.getShortName()} ") } println ("")
    

    輸出結果會顯示目前 Jenkins 所有安裝過的 Plugins 清單:

    jjwt-api git workflow-aggregator workflow-support git-client jdk-tool command-launcher pipeline-milestone-step msbuild ws-cleanup github okhttp-api mailer credentials plain-credentials github-branch-source pipeline-model-api display-url-api bouncycastle-api pipeline-github-lib momentjs ace-editor pipeline-input-step handlebars jquery3-api pipeline-rest-api pipeline-stage-tags-metadata bootstrap4-api workflow-multibranch cloudbees-folder workflow-cps-global-lib build-timeout antisamy-markup-formatter branch-api ant scm-api workflow-cps junit matrix-project pipeline-build-step pipeline-stage-step pipeline-model-extensions timestamper checks-api ssh-credentials font-awesome-api workflow-step-api git-server echarts-api lockable-resources email-ext matrix-auth apache-httpcomponents-client-4-api workflow-job ssh-slaves pipeline-graph-analysis ldap jsch pipeline-model-definition structs github-api workflow-api trilead-api popper-api credentials-binding gradle workflow-basic-steps snakeyaml-api plugin-util-api locale durable-task jackson2-api workflow-durable-task-step workflow-scm-step pipeline-stage-view resource-disposer token-macro pam-auth script-security
    

    請將執行結果的 Plugins 清單複製到剪貼簿

批次更新 Plugins 到最新版

  1. 設定 Jenkins Mirror Site (詳見 Jenkins on Windows 心得分享 (06):如何指定 Mirror 鏡像網站下載外掛 文章說明)

    export JENKINS_UC_DOWNLOAD=http://ftp.yz.yamagata-u.ac.jp/pub/misc/jenkins/
    
  2. 設定要安裝的 Plugins 清單

    export ALL_PLUGINS='jjwt-api git workflow-aggregator workflow-support git-client jdk-tool command-launcher pipeline-milestone-step msbuild ws-cleanup github okhttp-api mailer credentials plain-credentials github-branch-source pipeline-model-api display-url-api bouncycastle-api pipeline-github-lib momentjs ace-editor pipeline-input-step handlebars jquery3-api pipeline-rest-api pipeline-stage-tags-metadata bootstrap4-api workflow-multibranch cloudbees-folder workflow-cps-global-lib build-timeout antisamy-markup-formatter branch-api ant scm-api workflow-cps junit matrix-project pipeline-build-step pipeline-stage-step pipeline-model-extensions timestamper checks-api ssh-credentials font-awesome-api workflow-step-api git-server echarts-api lockable-resources email-ext matrix-auth apache-httpcomponents-client-4-api workflow-job ssh-slaves pipeline-graph-analysis ldap jsch pipeline-model-definition structs github-api workflow-api trilead-api popper-api credentials-binding gradle workflow-basic-steps snakeyaml-api plugin-util-api locale durable-task jackson2-api workflow-durable-task-step workflow-scm-step pipeline-stage-view resource-disposer token-macro pam-auth script-security'
    
  3. 使用 jenkins-plugin-cli 安裝 Plugins 外掛

    jenkins-plugin-cli --verbose -d $JENKINS_HOME/plugins/ --plugins $ALL_PLUGINS
    

    如果網路環境一定要透過 Proxy 來安裝 Plugins 的話,請到 Plugin Installation Manager Tool for Jenkins 下載 jenkins-plugin-manager-*.jar 檔案回來,啟動程式時給予 http.proxyPorthttp.proxyHost 指令(Directive)即可:

    java -Dhttp.proxyPort=3128 -Dhttp.proxyHost=myproxy.example.com -jar ./jenkins-plugin-manager-2.9.2.jar --verbose -d $JENKINS_HOME/plugins --plugins $ALL_PLUGINS
    

相關連結