Sri
Sri

Reputation: 479

Jenkins pipeline to call other pipeline stage

I am using Jenkins Pipeline and have a scenario where the expectation is:

In the pipeline job 'Test A' - Stage 'Checkout_A' it calls other pipeline job 'Test B' - Stage 'Checkout_B' , after that stage in Test B is completed the controller should retun back to pipeline job 'Test A' and execute Stage ('Build_A') which again calls pipeline job 'Test B' - Stage ('Build_B') then controller should retun back to pipeline job 'Test A' and execute Stage ('Transfer_A').

1)Below is the syntax i am using but its not working as above expected, appricate your inputs on how to achive this approach.

2)I want to use this approach mainly to show the pipeline different stages in upstream job itself instead of in downstream job. Is there any way or plugin available to show the stages of downstream job along with upstream job flow.

Test A
_______

Stage ('Checkout_A')
build job: 'Test B, stage: 'Checkout_B'', 
		  parameters: [string(name: 'GIT_URL', value: String.valueOf(ssh://git@xxx/aaa.git )),
		  string(name: 'CREDENTIALS', value: String.valueOf('xxxx123')
		   ] 
		  
Stage ('Build_A')
build job: 'Test B, stage: 'Build_B', 
		  parameters: [string(name: 'GIT_URL', value: String.valueOf(ssh://git@xxx/aaa.git )),
		  string(name: 'CREDENTIALS', value: String.valueOf('xxxx123')
		   ]

Stage ('Transfer_A')
build job: 'Test B', Stage: 'Transfer_B'

Test B
________

 stage 'Checkout_B'
          git (url: '${GIT_URL}',
          credentialsId: '${CREDENTIALS}')
		  build job: 'Test A, stage: Build_A'
		  
Stage ('Build_B')
        bat 'call "E:\\MSBuild\\12.0\\Bin\\MSBuild.exe" Sample.sln '
		  build job: 'Test A, stage: Transfer_A'
		  
Stage ('Transfer_B')
       Xcopy(Source, destination)

Upvotes: 1

Views: 4543

Answers (1)

StephenKing
StephenKing

Reputation: 37580

As you noticed, the build step has no parameter called stage. You simply cannot run arbitrary stages in other jobs - you can only trigger complete jobs, start to end. If you really want to separate that out (for reusability as well?), make the contents of the stage an extra job.

Regarding the visualization inline in the calling job: No, I wouldn't expect this to be possible soon. Have a look at the roadmap and you will only see the item that you actually get a link to go to the called job.

Upvotes: 1

Related Questions