Search code examples
jenkinsgroovyrtcjenkins-pipeline

How to use RTC plugin from jenkins pipeline groovy script?


I know I can use scm polling via a Jenkins RTC plugin, I'm just wondering if there's an example of how to do this via the groovy script for the pipeline plugin?

For example:

node{
   stage 'Checkout'
   git url: 'https://github.com/whatever/myrepo.git'
 ...
 }

Something like above but instead of git, you use rtc toolkit with prod url and specify a stream or a workspace... Cannot find an example anywhere and not sure how to go about implementing it via api (or if that's even possible?)


Solution

  • Actually the snippet generator is a bit misleading in that it does not generate all that you need. For example, based on what was generated I used this in the pipeline:

    node {
        teamconcert([buildDefinition: 'TestStream', value: 'buildDefinition'])
    }
    

    If you use it as is you will get this exception:

    RTC : checkout...
    [Pipeline] }
    [Pipeline] // node
    [Pipeline] End of Pipeline
    java.lang.NullPointerException
        at com.ibm.team.build.internal.hjplugin.RTCScm.checkout(RTCScm.java:1948)
        atorg.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:109)
        at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:83)
        at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:73)
        at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:52)
        at hudson.security.ACL.impersonate(ACL.java:221)
        at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:49)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
    

    The syntax that you require is this:

    node {
        teamconcert([
            buildType: [
                buildDefinition: 'TestStream',
                value: 'buildDefinition'
           ]
        ])
    }
    

    Team concert expects things to be wrapped in a 'buildType'. I found this in a forum answer on jazz.net, have not seen it documented anywhere else.