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!
workspaceinto agroovy variableand pass it as a parameter to the downstream job. How are you triggering the downstream job, you just need to add anargumentthere.env.variabledefine theString Variableon 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 whateverdefault valueis specifiedString Parameter. Also, you should paste pic of your parameters sections if you want further help. Reference st-g.de/2016/12/parametrized-jenkins-pipelines