Aggregating results of downstream is ‘no test’ in

2020-02-06 10:00发布

After running the main project, every downstream project has test result, but the "Latest Aggregated Test Result" is no tests. How to configure the Jenkins to make all the test results display in aggregated list?

标签: jenkins
2条回答
一纸荒年 Trace。
2楼-- · 2020-02-06 10:20

Aggregate downstream test results is not obvious, and not documented. The steps below are synthesized from How To Aggregate Downstream Test Results in Hudson.

For some reason, this shell command is not rendering below, at step 2 of b's configuration

xml='<testsuite tests="3">
<testcase classname="foo" name="ASuccessfulTest"/>
<testcase classname="foo" name="AnotherSuccessfulTest"/>
<testcase classname="foo" name="AFailingTest">
  <failure type="NotEnoughFoo"> details about failure </failure>
</testcase>
</testsuite>'

echo $xml > results.xml

To aggregate, you need to pass a finger-printed artifact from the upstream job to the downstream job. My solution for this was to install the Copy Artifact Plugin.

For my test setup, I've created two free-style jobs a and b.

a's configuration:

  1. Execute shell: echo $(date) > aggregate
  2. Aggregate downstream test results: check the Automatically aggregate... option
  3. Build other projects: set Projects to build to b
  4. Record fingerprints of files to track usage: set Files to fingerprint to aggregate (from the echo command above)

b's configuration:

  1. Copy artifacts from another project: set:
    1. Project name to a
    2. Which build to Upstream build that triggered this job
    3. Artifacts to copy: aggregate
    4. check Fingerprint Artifacts
  2. Execute shell: enter the xml=... command from above
  3. Publish JUnit test result report: set Test report XMLs to results.xml

This should be sufficient to have a aggregate b's test results. I'm not sure if there's a way/plugin to change a's status based on downstream results (like if b failed, then a would retroactively fail).

查看更多
家丑人穷心不美
3楼-- · 2020-02-06 10:30

For Scripted Pipeline, Say I have:

one upstream job - mainJob

two downstream jobs - downStreamJob1 and downStreamJob2.

To aggregate test result from downstreamJob1 and downStreamJob2, here is what the Jenkinsfile will look like:

downStreamJob1 Jenkinsfile - Archive and fingerprint the test result xml

archiveArtifacts allowEmptyArchive: true, 
artifacts: **/test-results/test/*.xml, 
fingerprint: true, defaultExcludes: false

downStreamJob2 Jenkinsfile - Archive and fingerprint the test result xml

archiveArtifacts allowEmptyArchive: true, 
artifacts: **/output/junit-report/*.xml,  
fingerprint: true, defaultExcludes: false

The artifacts path used Fileset to grab all test report XML. Read more about fileset HERE

mainJob Jenkinsfile - Copy artifact from each of the downstream jobs

copyArtifacts filter: 'build/test-result/test/*.xml', fingerprintArtifacts: true, projectName: 'downStreamJob1', selector: lastCompleted()

copyArtifacts filter: 'output/junit-report/*.xml', fingerprintArtifacts: true, projectName: 'downStreamJob2', selector: lastCompleted()

The best way to make sure you have the right path for filter and artifacts is to navigate to the artifact in each downstream job using this url $BUILD_URL/artifact/ where BUILD_URL is Full URL of this build, like http://server:port/jenkins/job/foo/15/

查看更多
登录 后发表回答