首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用令牌通过triggerRemoteJob()函数参数化远程作业

使用令牌通过triggerRemoteJob()函数参数化远程作业
EN

Stack Overflow用户
提问于 2020-10-20 18:01:32
回答 1查看 4.6K关注 0票数 2

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

我试图从调用远程作业的现有(使用curl)方法迁移一个基于令牌的作业,如下所示:

远程Jenkins设置:(我的服务器:8080)作业: MyPipelineFirstJob

代码语言:javascript
运行
复制
Under Job configuration  :  Build Triggers    -->    "Trigger builds remotely (e.g., from scripts)"   -->    Authentication Token    -->    108801

现有作业:On Local:

代码语言:javascript
运行
复制
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

New job on local :现在,我需要将上面的内容转换为使用参数化远程触发器插件。因此,除了远程主机等之外,我在全局配置中选择了Auth类型:“参数化远程触发器配置”

代码语言:javascript
运行
复制
"Enable 'build token root' support" is unchecked -- Do not know what this means
Authentication  -->  Bearer Token Authentication 

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

我调用以下功能来触发远程作业:

代码语言:javascript
运行
复制
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“,它说:

代码语言:javascript
运行
复制
BearerTokenAuth
    token (optional)
        Type: String

Build Failure:使用上面的配置,在构建作业时,我会得到以下错误:

代码语言:javascript
运行
复制
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字段,并将其作为参数的一部分传递:

代码语言:javascript
运行
复制
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"')

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

代码语言:javascript
运行
复制
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中附加的“作业”字:"buildByToken/job/buildWithParameters“吗?不知道为什么!

问题:

“correctly?

  • How令牌身份验证”的身份验证类型是与现有方法的要求相匹配的正确选项吗?

  • I是否传递参数

  • 以克服上述失败?
EN

回答 1

Stack Overflow用户

发布于 2020-10-21 10:56:06

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

代码语言:javascript
运行
复制
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')

Ref:下面的链接有一个使用"\n“作为参数分隔符的示例。

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

注意:上面的链接引用了代码段生成器。但是,生成器还不支持"triggerRemoteJob“!也许,我会更快地解决我的问题!

Jenkins版本: Jenkins 2.249.1

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

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64450933

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档