0

We're trying to start a downstream build which expects "UserName" and "UserPassword" as parameters.

withCredentials([usernamePassword( credentialsId: params.deployCredentialsId, usernameVariable: 'MY_USER', passwordVariable: 'MY_PASS', )]) { build(job: "deploy/nightly", parameters: [stringParam(name: "UserName", value: MY_USER), password(name: "UserPassword", value: MY_PASS), ... more parameters ) } 

but the downstream job never sees the UserName / UserPassword parameters. Is there a bug in the above definition, or should I look at the downstream job?

2 Answers 2

1

You need to look in the downstream job. It should have a 'parameters' block that looks like:

parameters { string(defaultValue: "", description: 'foo', name: "UserName") string(defaultValue: "", description: 'foo', name: "UserPassword") } 

Then in your stage you can do this:

stage('PrintParameter'){ steps{ sh 'echo ${UserName}' } } 
Sign up to request clarification or add additional context in comments.

1 Comment

I'll mark your answer as correct, even though in my case the cause was something else. Apparently the (blackbox) downstream job had a check on an unrelated property, and the fact that I was passing it UPPERCASE resulted in a failing credentials check, and the job ultimately asking for a password. Goes to say ... sometimes the cause is quite unrelated to the error message.
0

Let's say you have 2 Jenkins pipeline jobs called job-A and job-B and you want to call job-B from job-A by passing some parameters and you want to access those on job-B. The example would look like below:

job-A

pipeline { agent any; stages { stage('Build Job-B') { steps { build(job: "job-B", parameters: [string(name:"username",value: "user"),password(name:"password",value: "fake")], propagate: false, wait: true, quietPeriod: 5) } } } } 

job-B

pipeline { agent any; stages { stage('echo parameter') { steps { sh "echo $params" } } } } 

Note-

  1. params is by default available in all pipeline job, no matter whether you use a scripted pipeline or a declarative pipeline.

  2. you no need to define any parameter in the downstream job

2 Comments

Thanks for your reply, but the issue is not generally with parameters, those work fine. The only thing not working is to pass on the credentials.
you mean with this - parameters: [stringParam(name: "UserName", value: MY_USER), password(name: "UserPassword", value: MY_PASS) , MY_USER and MY_PASS environment variable is not being passed ? If that the case , try to change from MY_USER to "${env.MY_USER}" and MY_PASS to "${env.MY_PASS}".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.