【问题标题】:Parameterized remote job via triggerRemoteJob() function using Tokens通过使用令牌的 triggerRemoteJob() 函数参数化远程作业
【发布时间】:2020-10-22 14:29:29
【问题描述】:

尝试搜索几个网站,包括Parameterized remote job is triggered but console says failure

我正在尝试将基于令牌的作业从调用远程作业的现有(使用 curl)方法迁移到基于插件的调用,如下所示:

远程 Jenkins 设置:(myserver:8080) 工作:MyPipelineFirstJob

Under Job configuration  :  Build Triggers    -->    "Trigger builds remotely (e.g., from scripts)"   -->    Authentication Token    -->    108801

现有工作:本地 Jenkins:

curl -v --silent -X POST http://myserver:8080/job/MyPipelineFirstJob/buildWithParameters --data token=108801 --data RELEASE=9.2 --data ARCHITECTURE=ppc64le --data IP=9.99.999.99

新工作在本地 Jenkins 上: 现在,我需要翻译以上内容以使用 parameterized-remote-trigger-plugin。所以除了远程主机等,我在全局配置中选择了如下的Auth类型:“参数化远程触发配置”

"Enable 'build token root' support" is unchecked -- Do not know what this means
Authentication  -->  Bearer Token Authentication 

我看到一条警告消息“地址看起来不错,但无法建立连接。”

我正在调用以下函数来触发远程作业:

def handle = triggerRemoteJob(remoteJenkinsName: 'Perf_Jenkins_Server', job: 'MyPipelineFirstJob/buildByToken/buildWithParameters', auth: "108801", parameters: 'RELEASE=HMC9.2.951.2,ARCHITECTURE=ppc64le,HMC_MACHINE=9.99.999.9998') 

我已经根据这个网站https://www.jenkins.io/doc/pipeline/steps/Parameterized-Remote-Trigger/传递了字符串“108801”,上面写着:

BearerTokenAuth
    token (optional)
        Type: String

构建失败:使用上述配置,构建作业时,我收到此错误:

22:07:12  java.lang.ClassCastException: class org.jenkinsci.plugins.ParameterizedRemoteTrigger.pipeline.RemoteBuildPipelineStep.setAuth() expects class org.jenkinsci.plugins.ParameterizedRemoteTrigger.auth2.Auth2 but received class java.lang.String
22:07:12    at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:492)
22:07:12    at org.jenkinsci.plugins.structs.describable.DescribableModel.injectSetters(DescribableModel.java:429)
22:07:12    at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:331)
22:07:12    at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:269)
22:07:12    at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:179)
22:07:12    at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
22:07:12    at sun.reflect.GeneratedMethodAccessor493.invoke(Unknown Source)
22:07:12    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
22:07:12    at java.lang.reflect.Method.invoke(Method.java:508)

所以,我尝试删除 auth 字段,并将其作为参数的一部分传递:

def handle = triggerRemoteJob(remoteJenkinsName: 'Perf_Jenkins_Server', job: 'MyPipelineFirstJob/buildByToken/buildWithParameters', parameters: 'token="108801",RELEASE="HMC9.2.951.2",ARCHITECTURE=ppc64le,HMC_MACHINE="9.99.999.9998"')

注意:我还尝试在参数值周围添加双引号。进行了这些更改并尝试构建后,我收到以下错误:

22:19:12  ################################################################################################################
22:19:12    Parameterized Remote Trigger Configuration:
22:19:12      - job:                     MyPipelineFirstJob/buildByToken/buildWithParameters 
22:19:12      - remoteJenkinsName:       Perf_Jenkins_Server
22:19:12      - parameters:              [token="108801",RELEASE="HMC9.2.951.2",ARCHITECTURE=ppc64le,HMC_MACHINE="9.99.999.998"]
22:19:12      - blockBuildUntilComplete: true
22:19:12      - connectionRetryLimit:    5
22:19:12      - trustAllCertificates:    false
22:19:12  ################################################################################################################
22:19:12  Connection to remote server failed [404], waiting to retry - 10 seconds until next attempt. URL: http://myserver:8080/job/MyPipelineFirstJob/job/buildByToken/job/buildWithParameters/api/json, parameters: 
22:19:22  Retry attempt #1 out of 5
22:19:22  Connection to remote server failed [404], waiting to retry - 10 seconds until next attempt. URL: http://myserver:8080/job/MyPipelineFirstJob/job/buildByToken/job/buildWithParameters/api/json, parameters: 
22:19:32  Retry attempt #2 out of 5

你有没有注意到上面的o/p中额外的“job”字:“buildByToken/job/buildWithParameters”?不知道为什么!

问题:

  • “Bearer Token Authentication”的身份验证类型是否是与现有方法要求相匹配的正确选项?
  • 我是否正确传递了参数?
  • 如何克服上述故障?

【问题讨论】:

  • 首先,“job”参数应该是作业名称“job: 'MyPipelineFirstJob'”。只要你得到一个404错误,job name就是错误的......
  • @PatriceM.,好的,根据您的建议,构建失败且没有 404 错误:09:28:48 ERROR: Remote build failed with 'ExceedRetryLimitException' for the following reason: 'Max number of connection retries have been exeeded.'.

标签: jenkins jenkins-pipeline token


【解决方案1】:

找到解决方案:参数需要用新行分隔。不是逗号或空格。所以,我在每个参数之间添加了 '\n' 字符,如下所示,它起作用了!

def handle = triggerRemoteJob(remoteJenkinsName: 'Perf_Jenkins_Server', job: 'MyPipelineFirstJob', parameters: 'token=108801\nRELEASE=9.2.951.2\nARCHITECTURE=x86_64\nMACHINE_IP="9.99.999.998')

参考:以下链接有一个使用“\n”作为参数分隔符的示例。

https://github.com/jenkinsci/parameterized-remote-trigger-plugin/blob/master/README_PipelineConfiguration.md

注意:以上链接指的是代码片段生成器。但是,那个 Generator 还不支持“triggerRemoteJob”!也许,我会更快地解决我的问题!

Jenkins 版本:Jenkins 2.249.1
参数化远程触发插件版本:3.1.5.1

【讨论】:

  • 谢谢,@chhatrapati
  • 嗨,有类似的任务。我必须在远程 Jenkins 上执行另一项任务,但是当我尝试使用您的方法时,我得到了像 Expected named arguments but got [{and list of parameters}] 这样的错误。尝试不同的方法,我得到了expects class hudson.util.Secret but received class java.lang.String。你有不同的方法可以尝试。我使用令牌和用户进行身份验证,如果我将它与 curl 一起使用,它可以工作,但我需要让它与这个插件一起工作。有什么建议吗?
猜你喜欢
  • 1970-01-01
  • 2019-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-20
  • 1970-01-01
相关资源
最近更新 更多