Help needed: Pipeline, JiraIssueUpdater and SVN Groovy Script

578 views
Skip to first unread message

Oren Chapo

unread,
Sep 26, 2016, 11:53:42 AM9/26/16
to Jenkins Users
Hi everyone,

I have a working Jenkins setup (ver 2.23), with Pipeline jobs that use Subversion (SVN) to build and test various software components.
Jobs are triggered by polling SCM changes.
Most jobs use the same SVN tree, with different include/exclude filters for each job.
I also have a working JIRA configuration, and JIRA annotation seem to work OK (Jenkins detects mentions of JIRA keys in commit notes and displays them as links to JIRA items)

Now I want to add a JIRA comment to related items, probably using a JiraIssueUpdater, as described in https://github.com/jenkinsci/jira-plugin/blob/master/COMPATIBILITY.md#jiraissueupdater-usage-example
However the documentation gives only a partial snippet, specific to GIT (unfortunately I use SVN).
I'm also not sure how the object passed to JiraIssueUpdater should be used in an earlier "SVN checkout" step...
* Should I create a new SVN object, just for the JiraIssueUpdater step, or should I reuse the same object of the SVN checkout?
* If I should reuse the object, how should it be defined for SVN checkout?
* If not, how do I specify related filters (include/exclude), credentials etc. for the newly created "SVN" object?

The Jenkins "Snippet Generator" does not work for JIRA steps (creates a useless Groovy code).
I'm not a Groovy expert, and so far used mostly the "Snippet Generator" to create my Groovy scripts for builds.

Can anybody help me out?

Oren Chapo

unread,
Nov 9, 2016, 1:47:45 PM11/9/16
to Jenkins Users
Just got it, after some trial-and-error attempts. Basically I'm splitting the definition of the SCM object from the "checkout" command, and later re-use the SCM for both checkout and JiraIssueUpdater. Here's my small HOWTO:

  1. Use Jenkins' Snippet Generator: (Choose a Pipeline Job) -> Pipeline Syntax -> Snippet Generator -> Sample Step -> checkout: General SCM
    • Fill in the required fields for your SVN configuration
    • Click "Generate Pipeline Script".
    • You should get something like: 
    • checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[credentialsId: 'My-Credentials-Id', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: 'https://mysvn.mydomain']], workspaceUpdater: [$class: 'UpdateUpdater']])
  2. Convert the single line generated above into the following Groovy code (the common part copied from the generated snippet is marked in green):

       def svnScm = [$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[credentialsId: 'My-Credentials-Id', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: 'https://mysvn.mydomain']], workspaceUpdater: [$class: 'UpdateUpdater']]
       checkout(scm: svnScm)
       echo "Updating related JIRA items..."
       step([$class: 'hudson.plugins.jira.JiraIssueUpdater', issueSelector: [$class: 'hudson.plugins.jira.selector.DefaultIssueSelector'], scm: svnScm])
       svnScm = null

Hopefully, this saves someone else some time :-)

Reply all
Reply to author
Forward
0 new messages