-
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
Changes from all 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
0de6c07
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,113 @@ | ||||||
| /* 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 | ||||||
| * alwaysScript script to always 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 | ||||||
| * distro the distro to pass to daosRepos() if testRpmArgs does not specify a | ||||||
| * inst_repos, e.g. 'el9'; defaults to null | ||||||
| * 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) ?: [:] | ||||||
|
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. Is this not the same?
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. Not exactly:
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 would we have |
||||||
| Map testRpmArgs = kwargs.get('testRpmArgs', null) ?: [:] | ||||||
| String alwaysScript = kwargs.get('alwaysScript', '') | ||||||
| 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(kwargs.get('distro', null)) | ||||||
| } | ||||||
| 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 (alwaysScript) { | ||||||
| sh(script: alwaysScript, | ||||||
| label: "Running alwaysScript: ${alwaysScript}", | ||||||
| returnStatus: true) | ||||||
| } | ||||||
| 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}") | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
grom72 marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,112 @@ | ||||||||||||||||||
| /* 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 daosRepos() and unitPackages() when providing | ||||||||||||||||||
| * default arguments in unitTestArgs, 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; defaults to | ||||||||||||||||||
| * an empty Map. | ||||||||||||||||||
| * archiveArtifactsArgs Map of arguments to pass to archiveArtifacts() for the stage; defaults | ||||||||||||||||||
| * to an empty Map. | ||||||||||||||||||
| * @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) | ||||||||||||||||||
|
grom72 marked this conversation as resolved.
|
||||||||||||||||||
| } | ||||||||||||||||||
| if (!unitTestArgs.containsKey('inst_rpms')) { | ||||||||||||||||||
| /* groovylint-disable-next-line DuplicateStringLiteral */ | ||||||||||||||||||
| unitTestArgs['inst_rpms'] = unitPackages(target: distro) + ' daos-client-tests' | ||||||||||||||||||
| } | ||||||||||||||||||
|
grom72 marked this conversation as resolved.
grom72 marked this conversation as resolved.
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
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. The problem I see here (and in previous comments) is that we start using the
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. I do agree with @grom72 here. IMO it's better to not hardcode this kind of thing into pipeline-lib
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. The tricky part is that methods like This is something I think is better tackled in another PR - one where we could also consider using |
||||||||||||||||||
|
|
||||||||||||||||||
| 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}") | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why empty string instead of null?