diff --git a/Jenkinsfile b/Jenkinsfile index 5ea2172..6ca8664 100755 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -79,6 +79,11 @@ Sleep-seconds: 2''' } } // steps } //stage('env.COMMIT_MESSAGE pragma test') + stage('Unit tests') { + steps{ + trustedPipelineUnitTests() + } + } // stage('Unit tests') stage('DAOS Build and Test') { when { beforeAgent true diff --git a/vars/daosLatestVersion.groovy b/vars/daosLatestVersion.groovy index ae5f9ac..a7429c7 100644 --- a/vars/daosLatestVersion.groovy +++ b/vars/daosLatestVersion.groovy @@ -31,12 +31,16 @@ String distro2repo(String distro) { String getLatestVersion(String distro, BigDecimal next_version, String type='stable') { String v = null String repo = 'daos-stack-daos-' + distro2repo(distro) + '-x86_64-' + type + '-local/' + String artifactory_url = env.ARTIFACTORY_URL + /* For backwards support, add the 'artifactory' path if it is missing from the env */ + if (!artifactory_url.endsWith('/artifactory')) { + artifactory_url = "${artifactory_url}/artifactory" + } try { v = sh(label: 'Get RPM packages version for: ' + repo + ' with version < ' + next_version.toString(), - script: '$(command -v dnf) --refresh repoquery --repofrompath=daos,' + env.ARTIFACTORY_URL + - '/artifactory/' + repo + - ''' --repoid daos --qf %{version}-%{release} --whatprovides 'daos < ''' + - next_version + '''' | rpmdev-sort | tail -1''', + script: '$(command -v dnf) --refresh repoquery --repofrompath=daos,' + artifactory_url + '/' + + repo + ''' --repoid daos --qf "%{version}-%{release}\n" --whatprovides 'daos < ''' + + next_version + '''' | rpmdev-sort | tail -1''', returnStdout: true).trim() /* groovylint-disable-next-line CatchException */ } catch (Exception e) { diff --git a/vars/trustedPipelineUnitTests.groovy b/vars/trustedPipelineUnitTests.groovy new file mode 100644 index 0000000..946b4cd --- /dev/null +++ b/vars/trustedPipelineUnitTests.groovy @@ -0,0 +1,31 @@ +/* groovylint-disable DuplicateNumberLiteral, ParameterName, VariableName */ +// vars/trustedPipelineUnitTests.groovy + + /** + * trustedPipelineUnitTests.groovy + * + * Runs trusted-pipeline-lib unit tests + */ + +void call() { + // Run unit tests + _run_unit_tests() +} + +void _run_unit_tests() { + // Run all the unit tests + println('Test daosLatestVersion()') + _test_daosLatestVersion("master", "el8", /2.7\.\d++.*/) + _test_daosLatestVersion('release/2.6', 'el8', /2.[56]\.\d++.*/) +} + +void _test_daosLatestVersion(String distro, String next_version, String expected) { + // Verify the version returned by daosLatestVersion() matches expected + println(" Running daosLatestVersion(distro=${distro}, next_version=${next_version})") + result =daosLatestVersion(distro, next_version) + println(" result: ${result}") + println(" expected: ${expected}") + assert(result.matches(expected)) + println(" PASSED") + println("") +}