Publish a snapshot back to a RTC build result from a Jenkins build job
I am trying to publish a specific snapshot to a RTC build result. The build setup we use is as follows. We use Jenkins 2.x with Pipeline build scripts (pipeline script from scm). And the way we interact with builds is through build definitions setup in RTC (so developers submit build requests in RTC). The RTC build definition is pretty simple and just connects to a corresponding Jenkins build job. And as already mentioned the Jenkins build job uses a Pipeline build script from SCM.
Library('dcbldlib') _
checkout([$class: jazz.class, avoidUsingToolkit: jazz.toolkit, buildTool: jazz.tool, buildType: [buildStream: 'stream name', clearLoadDirectory: false, customizedSnapshotName: props.snapshotName, loadDirectory: props.loadDir, overrideDefaultSnapshotName: true, value: 'buildStream'], credentialsId: 'jenkins-creds-id', overrideGlobal: jazz.override, serverURI: jazz.uri, timeout: jazz.timeout])
3 answers
I would suggest to contact support and maybe open an enhancement request. It might be possible to achieve what you want using the API, however it would be nice if it was supported in the Jenkins Build.
Comments
Ouch. Not the answer I was hoping for. But regardless I appreciate your thoughts on this topic. I'll follow your advice and have our Rational Team contact support and open an enhancement request.
Rob,
an entrypoint into the API here is com.ibm.team.build.ant.task.tests.SnapshotPublisherTaskTests
com.ibm.team.build.ant.task.tests.SnapshotPublisherTaskTests.testSnapshotContributionAlreadyExists()
shows that part of the API.
Also search for Build Automation is https://rsjazz.wordpress.com/interesting-links/ and follw the links for other API examples.
If you are new to the API you want to follow https://rsjazz.wordpress.com/2015/09/30/learning-to-fly-getting-started-with-the-rtc-java-apis/
Thanks.
Since you should be able to publish arbitrary build results back to RTC, can't you just publish the snapshot URL back to RTC as one of your build results? (A file containing that snapshot URL string, for example). It won't show up nicely in the GUI in the RTC build result, but the information would be there for you to use.
Comments
That is certainly an option. Again not ideal, but it would provide the information in the build result. As you mention, you can publish anything back to the build result, so a snapshot URL could be constructed and published back to the build result.
Okay so I've established I can use this task to publish a link back to the build result: com.ibm.team.build.ant.task.ArtifactLinkPublisherTask
I see a couple of alternatives:
Okay using the RTC SCM CLI is another option. This option would probably require more in terms of setting up the plumbing etc., but seems like it would offer more control (at least clearer expected outcomes).
I know on the Jenkins side, the build job does "know" all the details about the RTC build information. When I review completed build jobs within the Jenkins console, all the snapshots are listed with the snapshot name as the label, and the URL of the snapshot as the link (and the correct snapshot UUID is included in that URL).
For some reason I cannot comment directly under your question or any of the answers. So, please don't take this as an answer :-)
I'm afraid I will fall into the same issue very soon, so I would like to know more about your configuration. I'm missing just few details on how you are checking out the Global Shared Libs and the Jenkins pipeline script.
This is how I would compose my environment...
Principles:
A - The tools around the build environment are "static". I don't want to get the latest state, I want a proven groovy code that handle/build my target project. Therefore, these tools are loaded from Snapshots.
B - The target project should be in its latest state. Therefore, Stream, RW or Build Definition (which in turn loads a RW).
Based on that,
1 - the Global Shared Libs are part of A, being loaded from a Snapshot.
2 - the Jenkins pipeline script is also part of A, loaded from a(nother) Snapshot.
3 - the actual project (B) is loaded using the Build Definition.
I would expect the Build Results for this configuration to contain a link to the corresponding checkout. That is, the Jenkins pipeline script (2) uses the Global Shared Libs (1) and triggers the checkout (3) using the Build Definition.
The last checkout is the one that creates the Build Result, so I would find very strange and counter-intuitive to have any Snapshot other than the one from (3).
Do you have a similar configuration?
If yes, which Snapshot do you see in your Build Result? 1, 2 or 3?
Would you have a Work Item number to share? I would happily vote on that.
Update: I'm able to convert the answer into Comment after posting it. Strange UX imho.
Update2: I can't edit a Comment after converting it from Answer. It has the "edit" button, but it pops a plain HTML page instead. Looks like bug.
Update3: I had to convert it back to Answer to be able to update the message. But now I'm unable to convert it to Comment again. Looks like another bug... The message will have to stay as "answer".
Comments
Not an answer...
Comments
Rob Leach
Aug 23 '17, 3:24 p.m.Exploring further I re-read the checkout step documentation and found this statement "This step returns a Map". Referring to the checkout Pipeline step itself.
Rob Leach
Sep 06 '17, 1:56 p.m.Here is the RFE:
Rob Leach
Oct 25 '17, 3:18 p.m.I wanted to follow up on this in case the information is useful to others. We've recently started exploring using Git for our SCM repository (GitLab, GitHub, Bitbucket, etc.). As a preliminary proof of concept we've stood up a GitLab instance and started migrating some source to repositories therein. One of the first things we migrated were the Jenkins Pipeline build scripts, the Jenkins Global Shared Library, and other build support scripts (Gradle, Ant, etc.). When we did this and plugged in all the requisite Pipeline pieces, we noticed that the build property team_scm_snapshotUUID now has the correct snapshot UUID, it no longer has the snapshot UUID from the Jenkins Global Shared Library fetch (as I've described in other comments). So clearly it seems that the issue revolves around the Jenkins Global Shared Library fetch which in our case occurred at the very beginning of the build process (first thing).
Rob Leach
Dec 06 '17, 1:15 p.m.https://jazz.net/jazz/web/projects/Rational%20Team%20Concert%20(SAFe)#action=com.ibm.team.workitem.viewWorkItem&id=446243
Lakshmi Narasimhan T V
JAZZ DEVELOPER Dec 07 '17, 11:29 a.m.Hi Rob,
Thanks for updating this post with the relevant work items.
With workflow-cps 2.40 and above, the env object is populated more than once. So the last checkout should have caused the team_scm_snapshotUUID to point to the snapshot of the stream. I have mentioned this in the wiki as well.