Query RTC change set details from Jenkins
Hi dear all,
I have a pipeline job that polls the SCM @ 5mins. It checks out and builds/tests etc. the source code on change (when there is a new change set pushed to the stream my job is following). All this works very well and I would like to add a few more features and please would require some expert advises. Many thanks.
1. Query for RTC change set details so I can perform actions such as selectively build and test code depending on where the change is made or email the person if the build is broken etc.
I cannot see this is possible using the Team Concert Plug-in because none of the environmental variables provide this data https://wiki.jenkins.io/display/JENKINS/Team+Concert+Plugin. E.g. buildRequesterUserId will always be a timer or will be the admin who may want to manually trigger the job and not the person who has pushed a change set. Is my conclusion right? It would have been great if I could get this info from the Plug in.
2. General environmental variables available to shell scripts:
The variable provided by Jenkins https://hudson.eclipse.org/webtools/env-vars.html/ looks very handy. BRANCH_NAME, CHANGE_ID, CHANGE_AUTHOR etc. are all great places for me to start. However, the description for these say that the project needs to be "Multi-branch" and that "if supported by SCM". Will I be able to use these variables for RTC integration? What are the things I need to watch out for?
3. I can see Jenkins is querying Change set details!
The "Changes" icon for a job, shows all the information I am after. I am aware this information is also logged as a file in the master. It wouldn't be ideal, but it is an option to scrape this data and use? But if Jenkins can access this info, so should I through my pipeline script? Is it advisable to use the RTC API? Do I need the SDK installed in that case? Kindly advise.
My configuration: The job in question is running on a single slave Windows machine. Master is a Linux server.
Jenkins version: 2.150.2
RTC version: 6.0.3
Jenkins-RTC integration - Team Concert Plug-in latest version.
Thanks for your continuous support. Please let me know if I missed to provide any information.!
|
One answer
After some for digging around, I have arrived at the following conclusions for now.
- Jenkins variables such as CHANGE_AUTHOR etc. is not updated by the Team concert plug-in. It just returns NULL.
- To get these details for a change set, I will either have to install the RTC SDK and use the Java APIs or extend RTC at the client to provide this data.
- The environment variables such as buildRequesterUserId provided by Team concert plug-in is not helpful, as my RTC build engine is following a repository created by a static user (created for Jenkins). buildRequesterUserId variable always reveals this same user no matter who has pushed the code. Makes sense.
So for now, I have found a working solution which is not the best but solves my need. Anyone facing the same problem, these are the steps below:
1. I make my Jenkins groovy switche to master node and make it to query for the RTC change log files, which is stored under $JENKINS_HOME/jobs/$JOB_NAME/builds/$BUILD_ID as an XML file for each build.
2. I copy the contents into a local variable in groovy and switch back to my agent node (slave). So no scp or pscp. I save contents into a file.
3. I parse the local file now, and extract information I require. E.g. email address of the user who has pushed the change etc. Perfect! :)
If anyone can suggest an alternate solution, please feel free to answer.
|
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.