【问题标题】:Jenkins Build with Parameter and authentication but no parameter valueJenkins 使用参数和身份验证构建但没有参数值
【发布时间】:2015-09-16 21:14:19
【问题描述】:

我尝试了多种方法来自动传递带有身份验证的 URL 和参数(来自使用参数插件的构建)以通过 wget 命令远程启动作业:

/usr/bin/wget --auth-no-challenge --http-user=<http-user> --http-password=<password like> http://<IP>:8080/job/<jobName>/buildWithParameters?token=<tokeName>&<param1>=<text1>

非参数化版本运行平稳,没有任何问题,但必要的&lt;param1&gt; 不适用于该作业。

在 build with pararmeters 作业中设置默认值,可以顺利运行作业,但会破坏通过脚本远程运行的目的。

这是一个经过净化的输出:

Started by remote host x.x.x.x
[EnvInject] - Loading node environment variables.
[EnvInject] - Preparing an environment for the build.
[EnvInject] - Keeping Jenkins system variables.
[EnvInject] - Keeping Jenkins build variables.
[EnvInject] - [ERROR] - The given properties file path '/var/lib/jenkins/<paramsFolder>/.properties' doesn't exist.
[EnvInject] - [ERROR] - Missing file path was resolved from pattern '/var/lib/jenkins/<paramsFolder>/${NAMESTR}.properties' .
ERROR: SEVERE ERROR occurs
org.jenkinsci.lib.envinject.EnvInjectException: java.io.IOException: The given properties file path '/var/lib/jenkins/<paramsFolder>/.properties' doesn't exist.

在作业的配置中,NAMESTR 被定义为一个字符串参数。当给定适当的默认值时,作业按预期运行。如果作业中没有默认值,则无法通过 wget 命令获得该作业的参数值,如上面的输出所示。

我必须具有身份验证和命令行方法才能将参数提供给作业。我无法与 Jenkins 用户界面交互以手动运行命令。

有什么想法吗?有解决办法吗?

【问题讨论】:

    标签: jenkins parameters jenkins-plugins


    【解决方案1】:

    尝试使用cURL,它对我来说就像做梦一样。

    curl -X POST http://localhost:8080/job/test_job/buildWithParameters?RandomUser=Tom --user admin:admin
    

    【讨论】:

    • 感谢您的帮助。我使用 curl 尝试了几个选项,但使用 API 令牌还没有成功。由于上面的 wget 版本使用 API 令牌、auth no challenge 和参数(键值对),因此我没有必要也可以使用 curl。
    【解决方案2】:

    使用Http request plugin

    选择Http Request表单添加构建步骤

    将您的网址粘贴到 URL 字段中

    Http模式中选择POST方法

    如果您想添加身份验证,请将身份验证详细信息更新到您的 Jenkins 配置全局设置

    【讨论】:

    • 实现需要使用wget之类的远程命令。此解决方案似乎对 Jenkins 用户界面上的设置和使用有效。
    【解决方案3】:

    我发现 wget 选项 --post data 适用于 BuildWithParameters 插件。

    /usr/bin/wget --auth-no-challenge --http-user=<http-user> --http-password=<password like> --post-data 'param1=text1' http://<IP>:8080/job/<job name>/buildWithParameters?token=<tokenName>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-03
      • 1970-01-01
      • 1970-01-01
      • 2017-06-09
      • 1970-01-01
      • 1970-01-01
      • 2011-01-10
      • 1970-01-01
      相关资源
      最近更新 更多