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.
The Pipeline build script uses a Jenkins global shared library using the following Pipeline syntax (on the first line of the Pipeline build script).
Then further down in the Pipeline build script there is a scm fetch (we use the General SCM checkout Jenkins Pipeline step). The fetch code looks like this:
Some builds have multiple scm fetches (one up to three is typical--these are in addition to the global shared library which happens at the very beginning of the build job). I can set (or override) a snapshot on each respective fetch (scm checkout) as you can see in the code example, and this works as expected. If I checkout a particular stream, I can confirm my snapshot is listed in the snapshot list for that stream.
However the problem is I cannot publish the correct snapshot back to the build result. From reading what IBM documentation I've found, I see that this property (or environment variable) is used for this task "team_scm_snapshotUUID". But when I try to publish the snapshot back to the build result I'm only getting the snapshot from the global shared library and nothing else.
How do I publish a specific snapshot back to a RTC build result (buildResultUUID)?
Or how can I get the snapshotUUID from a specific checkout to use to publish my snapshot back to a RTC build result?
This property, team_scm_snapshotUUID, only seems to contain the snapshot from the very first scm checkout (which in this case is the global shared library).
This is the task being used to perform the publish snapshot: com.ibm.team.build.ant.task.SnapshotPublisherTask
This is a related question found previously: https://jazz.net/forum/questions/236515/team_scm_snapshotuuid-environment-variable-overwritten-when-loading-jenkins-pipeline-library
|
3 answers
Ralph Schoon (63.7k●3●36●48)
| answered Aug 28 '17, 8:14 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER 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
Rob Leach
commented Aug 29 '17, 11:09 p.m.
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.
I'll still hold out hope that someone might be able to offer a work around solution. Even as Ralph outlined, using the API.
Ralph Schoon
commented Aug 30 '17, 2:05 a.m.
| edited Aug 30 '17, 2:05 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Rob,
Rob Leach
commented Aug 30 '17, 4:06 p.m.
Thanks. |
Geoffrey Clemm (30.1k●3●30●35)
| answered Aug 30 '17, 2:21 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER 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
Rob Leach
commented Aug 30 '17, 4:12 p.m.
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.
I'm sure I'll hear complaints about the snapshot not showing up as expected (as a valid build result snapshot), but as long as the information is available for the individual developers to consume. It would be something they locate in the build results links tab.
Thanks for the tip.
Rob Leach
commented Aug 30 '17, 9:42 p.m.
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
And I've established that this is the format of the URL for the snapshot: https://jazzcm.host:9445/ccm/resource/itemOid/com.ibm.team.scm.BaselineSet/_EN63uI3oEeejGvLjZrr0mA
But the last part of the URL is not known (this part: _EN63uI3oEeejGvLjZrr0mA), and I don't know how to get that. I've already established that the checkout for the RTC scm type does not return anything (contrary to the Jenkins checkout documentation).
It always seems to fall back to needing the snapshot UUID which is what I think this is, _EN63uI3oEeejGvLjZrr0mA.
Sigh.
Geoffrey Clemm
commented Aug 31 '17, 4:04 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
I see a couple of alternatives:
- Use the RTC scm command directly to perform the snapshot create, rather than using the Jenkins checkout_scm command.
- Ralph's suggestion to file an RTC enhancement request against the Jenkins Plugin category, asking for the URL or UUID of the snapshot created by the Jenkins checkout_scm command to be returned in the map returned by the checkout_scm command. Note that the documentation for the checkout_scm does not specify what should appear in this map, so you cannot count on anything specific being there (so the current behavior of returning nothing appears to comply with the spec for the command).
Rob Leach
commented Aug 31 '17, 10:16 a.m.
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 contacted our Rational Team support and explained the details of the issue. They decided to open a PMR (so that's done). I'll ask them why they chose that route....
Rob Leach
commented Aug 31 '17, 10:16 a.m.
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).
Again it always falls back to getting or accessing that snapshot UUID so I can consume it. The RTC Jenkins plugin is doing a lot of the right things, I just don't know how to get this one piece of information beyond what the documentation has to offer. Going the route of implementing my own library using the Java API seems excessive for such a simple use case (and somewhere under-the-covers that information is captured).
But you've both already stated an enhancement request probably seems the best course of action.
Thank you, both, again.
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.
Comments
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.
Here is the RFE:
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).
https://jazz.net/jazz/web/projects/Rational%20Team%20Concert%20(SAFe)#action=com.ibm.team.workitem.viewWorkItem&id=446243
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.