0

I have two pipeline jobs Job A and Job B. I need to pass the workspace url of Job A (say /var/lib/jenkins/workspace/JobA) to be used by Job B. The main idea is I am trying to copy the contents of target folder which is generated due to maven build but I don't want to use Copy Artifacts Plugin or Archive Artifacts Plugin to achieve the same.

I have tried using the option "This job is parameterized" where Job A is the upstream of Job B but i am unable to so using that option.

Can anyone help to achieve the same ?

Sourav
  • 3,025
  • 2
  • 13
  • 29

2 Answers2

0

The WORKSPACE variable is an env variable from Jenkins and is pointing like / .

For eg. 

If the job name is Job_A --> the workspace value will be <jenkins_path>/Job_A

For eg. 

If the job name is Job_B --> the workspace value will be <jenkins_path>/Job_B

So you can't use the WORKSPACE var and expects the Job_B to point to Job_A workspace value.

The below can be used to get certain properties from the upstream job.

Jenkins - How to get and use upstream info in downstream

Even if you want to hard code it in the Job_B it will be fine(not recommended) Also for this to work your node should be same for both the jobs

error404
  • 2,684
  • 2
  • 13
  • 21
  • How to display the WORKSPACE name of JobA in JobB ? I tried using echo "${env.WORKSPACE}" and also, echo "${params.WORKSPACE}. But none of this giving the exact output. – Sourav Apr 23 '20 at 06:19
0

I have found a way to do the same and it is working fine. I have made the Job B a parameterized job using "This project is parameterized" and used string parameter. enter image description here

Then, in the pipeline script of Job A, i invoked the Job B by passing WORKSPACE env variable. Here is the declarative pipeline script for Job A:

pipeline {
agent any
stages
{
    stage ('Build JobB')
    {
        steps {
          build job: 'jobB', parameters: [string(name: 'UPSTREAM_WORKSPACE', value: "${env.WORKSPACE}")]
        }
    }
} }

Now, in Job B pipeline you can try to echo the variable UPSTREAM_WORKSPACE. This is how we can pass the workspace url and use it to copy the artifacts.

Sourav
  • 3,025
  • 2
  • 13
  • 29