Reputation: 121
Tried to search a few sites, including Parameterized remote job is triggered but console says failure
I am attempting to migrate a token based job from existing (using curl) method of calling remote job to plugin based call as follows:
Remote Jenkins Setup: (myserver:8080) Job: MyPipelineFirstJob
Under Job configuration : Build Triggers --> "Trigger builds remotely (e.g., from scripts)" --> Authentication Token --> 108801
Existing job: On Local 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
New job on local Jenkins: Now, I need to translate the above to use parameterized-remote-trigger-plugin. So Apart from Remote Host, etc, I have chosen the Auth type as follows in the Global configuration: "Parameterized Remote Trigger Configuration"
"Enable 'build token root' support" is unchecked -- Do not know what this means
Authentication --> Bearer Token Authentication
I see a WARNING message as "Address looks good, but a connection could not be established."
I am calling the below funciton to trigger the remote job:
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')
I have passed the string "108801" based on this site https://www.jenkins.io/doc/pipeline/steps/Parameterized-Remote-Trigger/ which says:
BearerTokenAuth
token (optional)
Type: String
Build Failure: With the above configuration, when build the job, I get this error:
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)
So, I tried to remove the auth field, and passed it as part of parameters:
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"')
Note: I have also attempted to add double quotes around the parameter values. Having made these changes, and attempt to build, I get the following error:
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
Did you notice the additional "job" word : "buildByToken/job/buildWithParameters" in the above o/p? Not sure why!
Questions:
Upvotes: 3
Views: 8888
Reputation: 121
Found the solution: The parameters needs to be separated by a new line. Not a comma or space. So, I added '\n' char between each parameter as shown below and it worked!
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: The below link has an example that uses "\n" as parameter separator.
Note: The above link refers to Snippet Generator. However, that Generator doesn't support "triggerRemoteJob" yet! May be, I would have solved my issue faster!
Jenkins Version: Jenkins 2.249.1
Parameterized Remote Trigger Plugin Version: 3.1.5.1
Upvotes: 9