如何从命令行安装Jenkins插件?

e5njpo68  于 2023-02-21  发布在  Jenkins
关注(0)|答案(6)|浏览(241)

是否有任何选项从命令行安装Jenkins插件?
我找到了一个命令后,有点谷歌搜索:

java -jar /var/lib/jenkins/jenkins.war -s http://127.0.0.1:8080/ install-plugin ${Plugin_Name}

但它不起作用。

nafvub8i

nafvub8i1#

根据Jenkins command line interface documentation,您需要使用clientJAR文件(不是您正在使用的serverWAR文件),您可以直接从Jenkins获得该文件,例如通过http://localhost:8080/cli上的链接
然后,您可以使用以下JAR运行命令:

java -jar jenkins-cli.jar -s http://127.0.0.1:8080/ install-plugin <name>

这将下载安装你想要的插件,沿着它的任何依赖项.

yiytaume

yiytaume2#

import jenkins.model.* 
import java.util.logging.Logger

def logger = Logger.getLogger("") 
def installed = false 
def initialized = false

def pluginParameter="gitlab-plugin hipchat swarm" 
def plugins =pluginParameter.split() 
logger.info("" + plugins) 
def instance =Jenkins.getInstance() 
def pm = instance.getPluginManager() 
def uc =instance.getUpdateCenter() 
uc.updateAllSites()

plugins.each {   logger.info("Checking " + it)   if
(!pm.getPlugin(it)) {
    logger.info("Looking UpdateCenter for " + it)
    if (!initialized) {
      uc.updateAllSites()
      initialized = true
    }
    def plugin = uc.getPlugin(it)
    if (plugin) {
      logger.info("Installing " + it)
        plugin.deploy()
      installed = true
    }   } }

if (installed) 
   {  
      logger.info("Plugins installed, initializing a   restart!")   
       instance.save()  
       instance.doSafeRestart()
 }
kx5bkwkv

kx5bkwkv3#

自2019年9月起,你也可以使用Plugin Installation Manager Tool。它使用一个列出插件的yaml文件,并将插件下载到你选择的文件夹中。不需要有一个正在运行的Jenkins示例。你可以在yaml文件中指定插件版本,但要注意JENKINS-60205
获取插件管理器:

version=1.0.1
curl \
    -L \
    -X GET "https://github.com/jenkinsci/plugin-installation-manager-tool/releases/download/plugin-management-parent-pom-$version/jenkins-plugin-manager-$version.jar" \
    -o jenkins-plugin-manager-$version.jar

下载插件:

java -jar jenkins-plugin-manager-$version.jar \
    --plugin-download-directory pluginsFolder \
    --plugin-file plugins.yml \
    --war jenkins.war

插件在pluginsFolder中。

polkgigr

polkgigr4#

您将需要jenkins-cli.jar文件。该文件可从${JENKINSURL}/jnlpJars/jenkins-cli.jar下载

wget http://localhost:8080/jnlpJars/jenkins-cli.jar

要安装插件:

java -jar jenkins-cli.jar -auth ${USER}:${PASSWORD} -s ${JENKINSURL} install-plugin ${PLUGIN_NAME}

如果您不提供身份验证,则会收到错误:
错误:anonymous缺少总体/读取权限

5fjcxozz

5fjcxozz5#

如果你没有找到一些直接的命令来安装插件,请看这个链接:How to install a plugin in Jenkins manually?
但它需要先下载插件(*.hpi文件),然后手动运行。

lkaoscv7

lkaoscv76#

我的命令:

jenkins-plugin-cli --plugins "snyk-security-scanner:2.12.1 file-operations:1.11 branch-api:2.5.6 pipeline-build-step:2.13 workflow-support:3.8 aws-credentials:1.28 subversion:2.13.1 github-branch-source:2.7.1 publish-over-ftp:1.15 cloudbees-folder:6.740.ve4f4ffa_dea_54"

我在文件夹里用的那个

FROM jenkins/jenkins:lts

USER root

# Install custom plugins
RUN jenkins-plugin-cli --plugins "snyk-security-scanner:2.12.1 file-operations:1.11 branch-api:2.5.6 pipeline-build-step:2.13 workflow-support:3.8 aws-credentials:1.28 subversion:2.13.1 github-branch-source:2.7.1 publish-over-ftp:1.15 cloudbees-folder:6.740.ve4f4ffa_dea_54"

# Set environment variables
# ENV <ENV_VARIABLE_1> <VALUE>
# ENV <ENV_VARIABLE_2> <VALUE>

USER jenkins

相关问题