Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Bug when returning Files to a Build Result using Jenkins

 Hello,


I am using RTC 6.0.4, Jenkins 2.164.2 and Team Concert Jenkins Plugin 1.3.0 
 
I think I have found a bug in the RTC Jenkins Integration and am seeking a workaround.
I have setup polling from Jenkins which works fine and builds initiated from RTC work fine

I use a pipeline and within that a checkout of a build definition, the checkout step works fine and then I call an ANT script to return some files, that bit is broken.

When the build is initiated from RTC the buildResultUUID property is filled by RTC
When it is initiated from Jenkins it is probably overwritten by Jenkins somehow - anyway it's blank, ideally this would be filled by RTC after the checkout step runs.

The build result artifact is however definitely generated and I can get at the UUID using the
RTCBuildResultUUID variable which appears to be a twin of the buildResultUUID

Things do not work fine when the build is initiated from Jenkins 
What I have that others may not have is an ANT script that I run within a jenkins pipeline to return generated Results and logs to sit on the build result

I run ant using the batch step within a withCredentials and a withAnt block and pass the UUID successfully to the buildResultUUID ANT property 

ant -f build.xml -DbuildResultUUID=-ohjlkjhlkjhljkhlkjhkfddgf -.....

the UUID is correct when I check the incomplete result in RTC, it seems that I cannot write to the buildResult when the build is initiated from Jenkins. I get the following sort of error (something is not initiated properly on the build definition when it is initiated  from Jenkins, seems like a bug?):-

com.ibm.team.repository.common.itemNotFoundException: CRJAZ0215E The following record was not found in the database com.ibm.team.build.internal.common.model.impl.BuildResultHandelImpl@c7c4b5fc (stateId: null, itemId: [UUID _vhGsdfsfsdsdfsfsf], origin: <unset>, immutable: <unset>)

Note I check the UUID afterwards in RTC and it is as passed to the ANT file, very annoying ;-)

Any workaround suggestions?

Cheers
Richard
 

0 votes

Comments

Have you tried to echo the buildResultUUID property inside the ant script to see if the values match up? Or echo the value in the pipeline script and check the UUID value in the ItemNotFoundException message.

They match perfectly as far as I can see 

OK I echo the ant command I fire not the property within the ANT script, worth a go, however the GUID in the error message RTC says does not exist, does exist after the build is complete, just without my files and build label, so it's hard to see that being an issue, the error report sent from RTC is possibly bogus and there is over zealous error capture or the buildResult is in the wrong state.

I was hoping for someone to give me a lower level workaround without any need to reverse engineer this
Something like the following (I've made up the last bit ;-) )

def action = currentBuild.build().getAction(com.ibm.team.build.internal.hjplugin.RTCBuildResultAction.class)

def buildProps = action.addBuildResult(richardsFile.zip) etc

Reporting buildResultUUID in ANT script, it is correct and as expected, looks like a bug in RTC to me. Anyone from IBM got a suggested workaround. Note it sounds as though it has not been initiated when I try to write to it, but it could also have been closed down already. 

Hi Richard,
Want to clarify the flow in your build. The checkout runs first followed by your ant script. You retrieve the UUID of the build result from the RTCBuildResultUUID variable and pass it to your ant script.

You have echoed the value of the build result UUID in the pipeline script as well as in your ant script. They both match and it is the same UUID that is returned back in the exception message from RTC.

If possible can you please provide the snippet from your pipeline script that does the checkout and invokes the ant script, after hiding/overwriting any internal details?

Also if you have any Stacktrace from the exception, can you provide that too?

Thanks,
Sridevi

Yes that is my workflow, I have included some data to allow you to replicate my issue as well as the exception detail. I'm after a work around here, I'm sure there will be one. Thanks in advance for any help. 

showing 5 of 7 show 2 more comments

Accepted answer

Permanent link

 //def checkOutVars = checkout([$class: 'RTCScm', avoidUsingToolkit: false, buildTool: 'RTC 6.0.4', buildType: [buildDefinition: 'PCU-TSS build', customizedSnapshotName: '', value: 'buildDefinition'], credentialsId: 'bigNumber', overrideGlobal: true, serverURI: 'serverUrl', timeout: 480])

        def checkOutVars =teamconcert buildType: [buildDefinition: 'PCU-TSS build', value: 'buildDefinition'], overrideConfig: [buildTool: 'RTC 6.0.4', credentialsId: 'bigNumber', serverURI: 'serverUrl']

Any reason for using the teamconcert step and not the checkout step? teamconcert step is outdated. But I doubt if that would be the reason for the failure.

We have a similar setup in our test environment, where we invoke startBuildActivity and completeBuildActivilty from inside an ant script in a pipeline job. It works fine even when we run the build from Jenkins.

Can you please check if the repository address passed to the ant task is same when the build is requested from RTC as well as Jenkins?


Richard Good selected this answer as the correct answer

1 vote

Comments

I was trying teamconcert in my attempt to get this to work, I will swap back to checkout.


I'm now happy and sad at the same time, the repositoryAddress property in Jenkins is indeed  pointing at my test server not the production server. I didn't remember that this is overwritten by RTC when it is fired from RTC, changing the property to point at the production server allows it to work!

Glad that your problem is resolved!


3 other answers

Permanent link

Stack Trace:- 


com.ibm.team.repository.common.ItemNotFoundException: CRJAZ0215E The following record was not found in the database: com.ibm.team.build.internal.common.model.impl.BuildResultHandleImpl@c7c4b5fc (stateId: null, itemId: [UUID _vhG68ZaUEemwwtJiYVVnAQ], origin: <unset>, immutable: <unset>)
at com.ibm.team.repository.common.internal.marshal.util.MarshallerUtil.decodeExceptions(MarshallerUtil.java:369)
at com.ibm.team.repository.common.internal.marshal.util.MarshallerUtil.decodeExceptions(MarshallerUtil.java:339)
at com.ibm.team.repository.common.internal.marshal.util.MarshallerUtil.decodeFault(MarshallerUtil.java:304)
at com.ibm.team.repository.transport.client.RemoteTeamService.constructExceptionFromFault(RemoteTeamService.java:717)
at com.ibm.team.repository.transport.client.RemoteTeamService.executeMethod(RemoteTeamService.java:560)
at com.ibm.team.repository.transport.client.RemoteTeamService.invoke(RemoteTeamService.java:202)
at com.ibm.team.repository.transport.client.ServiceInvocationHandler.invoke(ServiceInvocationHandler.java:43)
at com.sun.proxy.$Proxy16.startBuildActivity(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
at java.lang.reflect.Method.invoke(Method.java:620)
at com.ibm.team.repository.client.internal.ServiceInterfaceProxy.invokeServiceCall(ServiceInterfaceProxy.java:254)
at com.ibm.team.repository.client.internal.ServiceInterfaceProxy.invoke(ServiceInterfaceProxy.java:110)
at com.sun.proxy.$Proxy16.startBuildActivity(Unknown Source)
at com.ibm.team.build.internal.client.TeamBuildClient$1StartBuildActivityRunnable.run(TeamBuildClient.java:315)
at com.ibm.team.process.internal.common.advice.runtime.OperationAdviceManager.runRunnable(OperationAdviceManager.java:1466)
at com.ibm.team.process.internal.common.advice.runtime.OperationAdviceManager.execute(OperationAdviceManager.java:208)
at com.ibm.team.process.internal.client.ProcessClientService.execute(ProcessClientService.java:774)
at com.ibm.team.build.internal.client.TeamBuildClient$9.run(TeamBuildClient.java:329)
at com.ibm.team.repository.client.internal.TeamRepository$3.run(TeamRepository.java:1328)
at com.ibm.team.repository.common.transport.CancelableCaller.call(CancelableCaller.java:79)
at com.ibm.team.repository.client.internal.TeamRepository.callCancelableService(TeamRepository.java:1323)
at com.ibm.team.build.internal.client.AbstractTeamBuildClient.callCancelableService(AbstractTeamBuildClient.java:268)
at com.ibm.team.build.internal.client.TeamBuildClient.startBuildActivity(TeamBuildClient.java:323)
at com.ibm.team.build.ant.task.StartBuildActivityTask.updateBuildResult(StartBuildActivityTask.java:153)
at com.ibm.team.build.ant.task.AbstractPublisherTask.doExecute(AbstractPublisherTask.java:105)
at com.ibm.team.build.ant.task.AbstractTeamBuildTask.execute(AbstractTeamBuildTask.java:1003)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
at java.lang.reflect.Method.invoke(Method.java:620)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
at org.apache.tools.ant.Main.runBuild(Main.java:758)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

0 votes


Permanent link
Pipeline script:-

def timestamp = Calendar.getInstance().getTime().format('YYYYMMdd-hhmm')

echo(timestamp)
def resultsFile=  outDir + '\DeployFolder' + timestamp +'.zip'
def deployZipFile = 'DeployFolder' + timestamp +'.zip'
def deployTermZipFile = 'Deploy_TermFolder' + timestamp +'.zip'
def bResult
echo(resultsFile)
node {
   def mvnHome
   stage('Preparation') { // for display purposes
         //def checkOutVars = checkout([$class: 'RTCScm', avoidUsingToolkit: false, buildTool: 'RTC 6.0.4', buildType: [buildDefinition: 'PCU-TSS build', customizedSnapshotName: '', value: 'buildDefinition'], credentialsId: 'bigNumber', overrideGlobal: true, serverURI: 'serverUrl', timeout: 480])
        def checkOutVars =teamconcert buildType: [buildDefinition: 'PCU-TSS build', value: 'buildDefinition'], overrideConfig: [buildTool: 'RTC 6.0.4', credentialsId: 'bigNumber', serverURI: 'serverUrl']
        echo("Check env version")
        bResult= "$env.RTCBuildResultUUID"
        buildResultUUID=bResult
        echo("${bResult}")
        echo env.buildEngineId
        echo env.repositoryAddress
        
        echo "SnapshotUUID"
        def snappy = "$env.team_scm_snapshotUUID"
        echo "${snappy}"
       
   }
    stage('Run Build') {
        dir(BuildDir) {
            bat label: '', script: 'deploy.bat'
            bat label: '', script: 'term_deploy.bat'
        }
    
    }
    stage('Results') {
    
    
        //changes current directory for any commands run inside it
        dir(buildDir) {
            //zip up folder contents to include on build
            zip archive: true, dir: './deploy', glob: '', zipFile: deployZipFile
            zip archive: true, dir: './term_deploy', glob: '', zipFile: deployTermZipFile
            //could include log files etc here, but information seems to go to standard out
        }
        //Polling does not work from RTC, the build runs every time regardless if there are changes, check
        if(buildResultUUID != "") {
            withCredentials([usernamePassword(credentialsId: 'somebigNumber', passwordVariable: 'password', usernameVariable: 'userId')]) {
                 dir(BuildDir) {
                    //If this build was ran from RTC then use ANT to store results 
                withAnt(installation: 'ANT-DEFAULT', jdk: 'IBMJDK') {
                   bat label: '', script: 'ant -f returnFilesAndLogs.xml -DrepositoryAddress=%repositoryAddress% -DbuildResultUUID=' + buildResultUUID + ' -DdeployResultsZip=' + deployZipFile + ' -DdeployTermResultsZip=' + deployTermZipFile + ' -DuserId=%userId% -Dpassword=%password% -lib C:\IBM\TeamConcert_6.0.4\TeamConcertBuild_6.0.4\buildsystem\buildtoolkit'
                }
                 }
            } 
       }
    }
}

0 votes


Permanent link

An ANT file to run:- 

<!--

This needs to be initiated from RTC in order to return things to a build result
Everything apart from the copying of results and log files back to RTC can be done better in
Jenkins
This bit will error if the build is run directly from Jenkins, maybe capture this by checking for 
null buildResultUUID in pipeline

password and userId are passed in using the withCredentials wrapper
-->

<project name="returnData" default="all">


<target name="all" depends="checkEnv">
<!-- Update the build progress in Jazz by starting a new build activity. -->
<startBuildActivity activityIdProperty="postResultsId"
                    label="posting Artefacts..."
                    buildResultUUID="${buildResultUUID}"
                    repositoryAddress="${repositoryAddress}"
                    userId="${userId}"
                    password="${password}" />



<!-- Publish some downloadable artifacts. Files published with the 
     artifactFilePublisher are shown on the Downloads tab of the build
     result editor. -->
<tstamp>
<format property="timePortion" pattern="yyyyMMdd-HHmm" />
</tstamp>
<artifactFilePublisher buildResultUUID="${buildResultUUID}"
                       repositoryAddress="${repositoryAddress}"
                       userId="${userId}"
                       password="${password}"
                       verbose="true"
                       filePath="${deployResultsZip}"
                       label="A suitable label" />
<artifactFilePublisher buildResultUUID="${buildResultUUID}"
                       repositoryAddress="${repositoryAddress}"
                       userId="${userId}"
                       password="${password}"
                       verbose="true"
                       filePath="${deployTermResultsZip}"
                       label="Another label" />
<buildResultPublisher  label="MyBuildLabel ${timePortion}"
   buildResultUUID="${buildResultUUID}"
                       repositoryAddress="${repositoryAddress}"
                       userId="${userId}"
                       password="${password}" />
   
<!-- Complete the compile build activity. -->
<completeBuildActivity activityId="${postResultsId}"
                       buildResultUUID="${buildResultUUID}"
                       repositoryAddress="${repositoryAddress}"
                       userId="${userId}"
                       password="${password}" />
</target>

<target name="checkEnv">
<fail message="The repositoryAddress property must be defined."
      unless="repositoryAddress" />
<echo message="Using repositoryAddress = ${repositoryAddress}" />
<fail message="The buildResultUUID property must be defined."
      unless="buildResultUUID" />
<echo message="Using buildResultUUID = ${buildResultUUID}" />
<fail message="The userId property must be defined." unless="userId" />
<echo message="Using userId = ${userId}" />

<fail message="The password property must be defined."
      unless="password" />
<!-- Don't echo the password. -->
</target>



<!-- These task definitions make the Jazz ant tasks available to this build file.
     In order to find these classnames at run time, ant must be invoked with:
     -lib <buildsystem-location>/buildtoolkit
-->
<taskdef name="buildResultPublisher"
         classname="com.ibm.team.build.ant.task.BuildResultPublisherTask" />
 
<taskdef name="artifactFilePublisher"
         classname="com.ibm.team.build.ant.task.ArtifactFilePublisherTask" />

<taskdef name="artifactLinkPublisher"
         classname="com.ibm.team.build.ant.task.ArtifactLinkPublisherTask" />

<taskdef name="filePublisher"
         classname="com.ibm.team.build.ant.task.FilePublisherTask" />

<taskdef name="jdtCompileLogPublisher"
         classname="com.ibm.team.build.ant.task.JdtCompileLogPublisherTask" />

<taskdef name="junitLogPublisher"
         classname="com.ibm.team.build.ant.task.JUnitLogPublisherTask" />

<taskdef name="linkPublisher"
         classname="com.ibm.team.build.ant.task.LinkPublisherTask" />

<taskdef name="logPublisher"
         classname="com.ibm.team.build.ant.task.LogPublisherTask" />

<taskdef name="startBuildActivity"
         classname="com.ibm.team.build.ant.task.StartBuildActivityTask" />

<taskdef name="completeBuildActivity"
         classname="com.ibm.team.build.ant.task.CompleteBuildActivityTask" />

</project>

0 votes

Your answer

Register or log in to post 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 562
× 151
× 63

Question asked: Jun 25 '19, 2:52 a.m.

Question was seen: 3,360 times

Last updated: Jun 26 '19, 6:12 a.m.

Confirmation Cancel Confirm