-
Notifications
You must be signed in to change notification settings - Fork 3
DAOS-19247 test: Support scripted Test stages #526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 26 commits
5db34af
ef5d151
09d02ef
0f14bd5
d677368
82667f5
ffc879a
5afdaea
b22f783
89f8bc1
acce7e9
efb52c0
ab0e990
633079a
304ab81
8cf3e29
61a43af
1a3cdef
1950b3a
3e2f4fc
037d0dd
8d53241
9deead5
0162051
6b92bcf
3c8c2dc
8130ede
495d93a
8e3ed9d
9b496bb
0c45b16
ffae8de
ad7d418
8fa926a
021404b
a5583e1
e38a6a5
db18bdc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /* groovylint-disable NestedBlockDepth */ | ||
| // vars/scriptedTestRpmStage.groovy | ||
|
|
||
| import org.jenkinsci.plugins.pipeline.modeldefinition.Utils | ||
|
|
||
| /** | ||
| * scriptedTestRpmStage.groovy | ||
| * | ||
| * Get a test stage in scripted syntax. | ||
| * | ||
| * @param kwargs Map containing the following optional arguments (empty strings yield defaults): | ||
| * name test stage name | ||
| * runStage whether or not to run the test stage; defaults to true | ||
| * label test stage default cluster label | ||
| * testBranch if specified, checkout sources from this branch before running tests; | ||
| * defaults to '' | ||
| * jobStatus Map of status for each stage in the job/build | ||
| * testRpmArgs Map of arguments to pass to testRpm() for the stage | ||
| * postScript script to run after the test stage, e.g. | ||
| * 'ci/rpm/test_daos_post.sh'; defaults to ''. | ||
| * archiveArtifactsArgs Map of arguments to pass to archiveArtifacts() for the stage | ||
| * next_version next daos package version to pass to daosPackagesVersion() if | ||
| * testRpmArgs does not specify a daos_pkg_version; defaults to null | ||
| * @return a scripted stage to run in a pipeline | ||
| */ | ||
| Map call(Map kwargs = [:]) { | ||
| // General parameters | ||
| String name = kwargs.get('name', '') | ||
| Boolean runStage = kwargs.get('runStage', true) as Boolean | ||
| String label = kwargs.get('label') | ||
| String testBranch = kwargs.get('testBranch', '') | ||
| Map jobStatus = kwargs.get('jobStatus', null) ?: [:] | ||
| Map testRpmArgs = kwargs.get('testRpmArgs', null) ?: [:] | ||
| String postScript = kwargs.get('postScript', '') | ||
| Map archiveArtifactsArgs = kwargs.get('archiveArtifactsArgs', null) ?: [:] | ||
|
|
||
| if (!name) { | ||
| error("scriptedTestRpmStage() requires a stage 'name' argument") | ||
| } | ||
|
|
||
| return { | ||
| stage("${name}") { | ||
| if (!runStage) { | ||
| println("[${name}] Stage skipped by runStage=false") | ||
| Utils.markStageSkippedForConditional("${name}") | ||
| return | ||
| } | ||
|
|
||
| // Add defaults for any missing testRpm() arguments | ||
| if (!testRpmArgs.containsKey('inst_repos')) { | ||
| /* groovylint-disable-next-line DuplicateStringLiteral */ | ||
| testRpmArgs['inst_repos'] = daosRepos() | ||
| } | ||
| if (!testRpmArgs.containsKey('daos_pkg_version')) { | ||
| /* groovylint-disable-next-line DuplicateStringLiteral */ | ||
| testRpmArgs['daos_pkg_version'] = daosPackagesVersion( | ||
| kwargs.get('next_version', null)) | ||
| } | ||
|
|
||
| node(label) { | ||
| // Ensure access to any branch provisioning scripts exist | ||
| if (testBranch) { | ||
| println("[${name}] Check out '${testBranch}' from version control") | ||
| checkoutScm( | ||
| url: 'https://github.com/daos-stack/daos.git', | ||
| branch: testBranch, | ||
| withSubmodules: false, | ||
| pruneStaleBranch: true) | ||
| } else { | ||
| println("[${name}] Check out branch from version control") | ||
| checkoutScm(pruneStaleBranch: true) | ||
| } | ||
|
|
||
| Throwable tryError = null | ||
| try { | ||
| println("[${name}] Running testRpm() on ${label}") | ||
| jobStatusUpdate(jobStatus, name, testRpm(testRpmArgs)) | ||
| /* groovylint-disable-next-line CatchException */ | ||
| } catch (Exception e) { | ||
| tryError = e | ||
| println("[${name}] Caught exception in try: ${tryError}") | ||
| jobStatusUpdate(jobStatus, name, 'FAILURE') | ||
| throw tryError | ||
| } finally { | ||
| try { | ||
| if (postScript) { | ||
| sh(script: postScript, label: "Running postScript: ${postScript}") | ||
| } | ||
| if (archiveArtifactsArgs) { | ||
| println("[${name}] Running archiveArtifacts()") | ||
| archiveArtifacts(archiveArtifactsArgs) | ||
| } | ||
| jobStatusUpdate(jobStatus, name) | ||
| /* groovylint-disable-next-line CatchException */ | ||
| } catch (Exception finallyError) { | ||
| println("[${name}] Caught exception in finally: ${finallyError}") | ||
| /* groovylint-disable-next-line DuplicateStringLiteral */ | ||
| jobStatusUpdate(jobStatus, name, 'FAILURE') | ||
| if (tryError == null) { | ||
| /* groovylint-disable-next-line ThrowExceptionFromFinallyBlock */ | ||
| throw finallyError | ||
| } | ||
| } | ||
| } | ||
| } | ||
| println("[${name}] Finished with ${jobStatus}") | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,109 @@ | ||||||||||||||||||
| /* groovylint-disable NestedBlockDepth */ | ||||||||||||||||||
| // vars/scriptedUnitTestStage.groovy | ||||||||||||||||||
|
|
||||||||||||||||||
| import org.jenkinsci.plugins.pipeline.modeldefinition.Utils | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * scriptedUnitTestStage.groovy | ||||||||||||||||||
| * | ||||||||||||||||||
| * Get a unit test stage in scripted syntax. | ||||||||||||||||||
| * | ||||||||||||||||||
| * @param kwargs Map containing the following optional arguments (empty strings yield defaults): | ||||||||||||||||||
| * name test stage name | ||||||||||||||||||
| * runStage whether or not to run the test stage | ||||||||||||||||||
| * label test stage default cluster label | ||||||||||||||||||
| * testBranch if specified, checkout sources from this branch before running tests | ||||||||||||||||||
| * jobStatus Map of status for each stage in the job/build | ||||||||||||||||||
| * distro the distro to use for the test stage, e.g. 'el9'; defaults to '' | ||||||||||||||||||
| * unitTestArgs Map of arguments to pass to unitTest; defaults to an empty Map. | ||||||||||||||||||
| * unitTestPostArgs Map of arguments to pass to unitTestPost() for the stage | ||||||||||||||||||
| * archiveArtifactsArgs Map of arguments to pass to archiveArtifacts() for the stage | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 8130ede |
||||||||||||||||||
| * @return a scripted stage to run in a pipeline | ||||||||||||||||||
|
grom72 marked this conversation as resolved.
|
||||||||||||||||||
| */ | ||||||||||||||||||
| Map call(Map kwargs = [:]) { | ||||||||||||||||||
| // General parameters | ||||||||||||||||||
| String name = kwargs.get('name', '') | ||||||||||||||||||
| Boolean runStage = kwargs.get('runStage', true) as Boolean | ||||||||||||||||||
| String label = kwargs.get('label') | ||||||||||||||||||
| String testBranch = kwargs.get('testBranch', '') | ||||||||||||||||||
| Map jobStatus = kwargs.get('jobStatus', null) ?: [:] | ||||||||||||||||||
| String distro = kwargs.get('distro', '') | ||||||||||||||||||
|
|
||||||||||||||||||
| // Unit Test stage parameters | ||||||||||||||||||
| Map unitTestArgs = kwargs.get('unitTestArgs', null) ?: [:] | ||||||||||||||||||
| Map unitTestPostArgs = kwargs.get('unitTestPostArgs', null) ?: [:] | ||||||||||||||||||
| Map archiveArtifactsArgs = kwargs.get('archiveArtifactsArgs', null) ?: [:] | ||||||||||||||||||
|
|
||||||||||||||||||
| if (!name) { | ||||||||||||||||||
| error("scriptedUnitTestStage() requires a stage 'name' argument") | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| return { | ||||||||||||||||||
| stage("${name}") { | ||||||||||||||||||
| if (!runStage) { | ||||||||||||||||||
| println("[${name}] Stage skipped by runStage=false") | ||||||||||||||||||
| Utils.markStageSkippedForConditional("${name}") | ||||||||||||||||||
| return | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // Add defaults for any missing unitTest() arguments | ||||||||||||||||||
| if (!unitTestArgs.containsKey('inst_repos')) { | ||||||||||||||||||
| /* groovylint-disable-next-line DuplicateStringLiteral */ | ||||||||||||||||||
| unitTestArgs['inst_repos'] = daosRepos(distro) | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a DAOS PR that removes these defaults from Jenkinsfile?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the change is for daos-stack/daos#18597 and the |
||||||||||||||||||
| } | ||||||||||||||||||
| if (!unitTestArgs.containsKey('inst_rpms')) { | ||||||||||||||||||
| /* groovylint-disable-next-line DuplicateStringLiteral */ | ||||||||||||||||||
| unitTestArgs['inst_rpms'] = unitPackages(target: distro) + ' daos-client-tests' | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+52
to
+60
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be better to fix
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR is a prerequisite for the daos-stack/daos#18597 where the If in the future we decide to use this for other unit test stages I think we can investigate other options for providing
Comment on lines
+52
to
+60
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have DAOS PR that removes this default from Jenkinsfile?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the change is for daos-stack/daos#18597 and the
Comment on lines
+57
to
+60
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we add
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is needed for the |
||||||||||||||||||
|
|
||||||||||||||||||
| node(label) { | ||||||||||||||||||
| // Ensure access to any branch provisioning scripts exist | ||||||||||||||||||
| if (testBranch) { | ||||||||||||||||||
| println("[${name}] Check out '${testBranch}' from version control") | ||||||||||||||||||
| checkoutScm( | ||||||||||||||||||
| url: 'https://github.com/daos-stack/daos.git', | ||||||||||||||||||
| branch: testBranch, | ||||||||||||||||||
| withSubmodules: false, | ||||||||||||||||||
| pruneStaleBranch: true) | ||||||||||||||||||
| } else { | ||||||||||||||||||
| println("[${name}] Check out branch from version control") | ||||||||||||||||||
| checkoutScm(pruneStaleBranch: true) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| Throwable tryError = null | ||||||||||||||||||
| try { | ||||||||||||||||||
| println("[${name}] Running unitTest() on ${label}") | ||||||||||||||||||
| jobStatusUpdate(jobStatus, name, unitTest(unitTestArgs)) | ||||||||||||||||||
| /* groovylint-disable-next-line CatchException */ | ||||||||||||||||||
| } catch (Exception e) { | ||||||||||||||||||
| tryError = e | ||||||||||||||||||
| println("[${name}] Caught exception in try: ${tryError}") | ||||||||||||||||||
| jobStatusUpdate(jobStatus, name, 'FAILURE') | ||||||||||||||||||
| throw tryError | ||||||||||||||||||
| } finally { | ||||||||||||||||||
| try { | ||||||||||||||||||
| if (unitTestPostArgs) { | ||||||||||||||||||
| println("[${name}] Running unitTestPost()") | ||||||||||||||||||
| unitTestPost(unitTestPostArgs) | ||||||||||||||||||
| } | ||||||||||||||||||
| if (archiveArtifactsArgs) { | ||||||||||||||||||
| println("[${name}] Running archiveArtifacts()") | ||||||||||||||||||
| archiveArtifacts(archiveArtifactsArgs) | ||||||||||||||||||
| } | ||||||||||||||||||
| jobStatusUpdate(jobStatus, name) | ||||||||||||||||||
| /* groovylint-disable-next-line CatchException */ | ||||||||||||||||||
| } catch (Exception finallyError) { | ||||||||||||||||||
| println("[${name}] Caught exception in finally: ${finallyError}") | ||||||||||||||||||
| /* groovylint-disable-next-line DuplicateStringLiteral */ | ||||||||||||||||||
| jobStatusUpdate(jobStatus, name, 'FAILURE') | ||||||||||||||||||
| if (tryError == null) { | ||||||||||||||||||
| /* groovylint-disable-next-line ThrowExceptionFromFinallyBlock */ | ||||||||||||||||||
| throw finallyError | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| println("[${name}] Finished with ${jobStatus}") | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.