0

I have Upstream job A, passing "workspace" parameter to upstream job A. So, if job A triggers job B, it should use the job A specified workspace. The job B also needs to run independently, in that case it should use its own workspace.

In job B, I have specified string parameter name UPWORKSPACE and default value "unspecified", which is for reading the upstream job workspace parameter.


Job A:

agent { stages { agent { label 'test' } stages { stage ('Invoke_pipelineA') { steps { build job: '/Job B', parameters: [ string(name: 'UPWorkspace', value: "${env.WORKSPACE}") ], wait: true } } 

job B: This project is parameterized: String Parameter Name: UPWorkspace Default Value : notspecified.

 pipeline { agent none stages { stage("checkout ") { agent { node{ label "test" customWorkspace "${UPWorkspace}" } } steps { echo "WORKSPACE: ${paramWorkspace}" } } } 

when Job A, triggers job B , its working fine, i could able to use custom workspace path, But if Job run independently i to tell job B to use normal workspace ?

Ideal solution would be if i am able to specify default value: env.WORKSPACE , in Job B, its perfect, but seems its not working.


some thing like this might be helpful, but i can't make it work in pipeline.

 if (params.UPWORKSPACE != "notspecified") //use custom workspace when default is not "notspecified" { customWorkspace "${UPWORKSPACE}" } 

Any help is appreciated. thanks!

8
  • In Job1, you can simply save the workspace into a groovy variable and pass it as a parameter to the downstream job. How are you triggering the downstream job, you just need to add an argument there. Commented Jul 25, 2020 at 10:08
  • I am already doing that. In job1 Iam passing the workspace as variable (UPWORKSPACE) to job2. For triggering downstreamjob something like this: node: { build job: 'job2', parameters: [[$class: 'StringParameterValue', name: 'UPWORKSPACE', value: /0pt/jenkins]] } Commented Jul 25, 2020 at 13:10
  • Unfortunately your question is not having complete details. Maybe you can post the complete pipelines from both jobs. This may help you: stackoverflow.com/questions/36306883/… Commented Jul 25, 2020 at 15:49
  • i have updated my query for better understanding. may be its bit more clear . Commented Jul 27, 2020 at 13:08
  • 1
    Don't take it as an env.variable define the String Variable on top as a parameter and it will be a parameterized build always. If parent job triggers it will use that workspace, else it will use whatever default value is specified String Parameter. Also, you should paste pic of your parameters sections if you want further help. Reference st-g.de/2016/12/parametrized-jenkins-pipelines Commented Jul 28, 2020 at 8:21

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.