Skip to content

Commit

Permalink
Update parameter requirement for manifest-commit-lock workflow (#5067)
Browse files Browse the repository at this point in the history
Signed-off-by: Divya Madala <[email protected]>
  • Loading branch information
Divyaasm authored Oct 2, 2024
1 parent 2273367 commit 1ac678e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ pipeline {
currentBuild.result = 'ABORTED'
error('MANIFEST_LOCK_ACTION and/or RELEASE_VERSION cannot be empty!')
}
if ((params.MANIFEST_LOCK_ACTION == 'MATCH_BUILD_MANIFEST' || params.MANIFEST_LOCK_ACTION == 'UPDATE_TO_RECENT_COMMITS') && (OPENSEARCH_RELEASE_CANDIDATE.isEmpty() || OPENSEARCH_DASHBOARDS_RELEASE_CANDIDATE.isEmpty())) {
if (params.MANIFEST_LOCK_ACTION == 'MATCH_BUILD_MANIFEST' && (OPENSEARCH_RELEASE_CANDIDATE.isEmpty() || OPENSEARCH_DASHBOARDS_RELEASE_CANDIDATE.isEmpty())) {
currentBuild.result = 'ABORTED'
error('OPENSEARCH_RELEASE_CANDIDATE and/or OPENSEARCH_DASHBOARDS_RELEASE_CANDIDATE cannot be empty when MANIFEST_LOCK_ACTION is MATCH_BUILD_MANIFEST or UPDATE_TO_RECENT_COMMITS.')
error('OPENSEARCH_RELEASE_CANDIDATE and/or OPENSEARCH_DASHBOARDS_RELEASE_CANDIDATE cannot be empty when MANIFEST_LOCK_ACTION is MATCH_BUILD_MANIFEST.')
}
}
}
Expand Down Expand Up @@ -112,7 +112,7 @@ pipeline {
}
steps {
script {
def updateManifest = { String productName, String releaseCandidate ->
def updateManifest = { String productName ->
def existingManifest = readYaml file: "manifests/${params.RELEASE_VERSION}/${productName}-${params.RELEASE_VERSION}.yml"
def selectedComponents = params.COMPONENTS.isEmpty() ? existingManifest.components : existingManifest.components.findAll { component ->
params.COMPONENTS.split(',').any { it.trim() == component.name }
Expand All @@ -136,8 +136,8 @@ pipeline {
sed -i '1s/^/---\\n/' manifests/${params.RELEASE_VERSION}/${productName}-${params.RELEASE_VERSION}.yml
"""
}
updateManifest("opensearch", params.OPENSEARCH_RELEASE_CANDIDATE)
updateManifest("opensearch-dashboards", params.OPENSEARCH_DASHBOARDS_RELEASE_CANDIDATE)
updateManifest("opensearch")
updateManifest("opensearch-dashboards")
}
}
}
Expand Down
23 changes: 21 additions & 2 deletions tests/jenkins/TestReleaseManifestCommitLock.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ class TestReleaseManifestCommitLock extends BuildPipelineTest {

super.setUp()
addParam('RELEASE_VERSION', '2.0.0')
addParam('OPENSEARCH_RELEASE_CANDIDATE', '3813')
addParam('OPENSEARCH_DASHBOARDS_RELEASE_CANDIDATE', '3050')
addParam('COMPONENTS', 'OpenSearch')

helper.registerAllowedMethod("withCredentials", [Map])
def buildManifest = "tests/jenkins/data/opensearch-2.0.0.yml"
helper.registerAllowedMethod('error', [String], { String message ->
throw new Exception(message)
})
helper.registerAllowedMethod('readYaml', [Map.class], { args ->
return new Yaml().load((buildManifest as File).text)
})
Expand All @@ -49,13 +50,27 @@ class TestReleaseManifestCommitLock extends BuildPipelineTest {
@Test
public void testManifestCommitLock_matchBuildManifest() {
addParam('MANIFEST_LOCK_ACTION', 'MATCH_BUILD_MANIFEST')
addParam('OPENSEARCH_RELEASE_CANDIDATE', '3813')
addParam('OPENSEARCH_DASHBOARDS_RELEASE_CANDIDATE', '3050')
super.testPipeline('jenkins/release-workflows/release-manifest-commit-lock.jenkinsfile',
'tests/jenkins/jenkinsjob-regression-files/release-workflows/testManifestCommitLock_matchBuildManifest')
def callStack = helper.getCallStack()
assertCallStack().contains('stage(Parameters Check, groovy.lang.Closure)')
assertCallStack().contains('stage(MATCH_BUILD_MANIFEST, groovy.lang.Closure)')
}

@Test
public void testManifestCommitLock_matchBuildManifest_exception() {
addParam('MANIFEST_LOCK_ACTION', 'MATCH_BUILD_MANIFEST')
binding.setVariable('OPENSEARCH_RELEASE_CANDIDATE', '')
binding.setVariable('OPENSEARCH_DASHBOARDS_RELEASE_CANDIDATE', '')
Exception exception = assertThrows(Exception) {
runScript('jenkins/release-workflows/release-manifest-commit-lock.jenkinsfile')
}
def callStack = helper.getCallStack()
assertCallStack().contains('OPENSEARCH_RELEASE_CANDIDATE and/or OPENSEARCH_DASHBOARDS_RELEASE_CANDIDATE cannot be empty when MANIFEST_LOCK_ACTION is MATCH_BUILD_MANIFEST.')
}

@Test
public void testManifestCommitLock_updateToRecentCommits() {
addParam('MANIFEST_LOCK_ACTION', 'UPDATE_TO_RECENT_COMMITS')
Expand All @@ -81,6 +96,8 @@ class TestReleaseManifestCommitLock extends BuildPipelineTest {

@Test
public void testManifestCommitLock_createPullRequest() {
addParam('OPENSEARCH_RELEASE_CANDIDATE', '3813')
addParam('OPENSEARCH_DASHBOARDS_RELEASE_CANDIDATE', '3050')
super.testPipeline('jenkins/release-workflows/release-manifest-commit-lock.jenkinsfile',
'tests/jenkins/jenkinsjob-regression-files/release-workflows/testManifestCommitLock_createPullRequest')
assertThat(getShellCommands('git'), hasItem("\n git remote set-url origin \"https://opensearch-ci:[email protected]/opensearch-project/opensearch-build\"\n git config user.email \"[email protected]\"\n git config user.name \"opensearch-ci\"\n git checkout -b manifest-lock\n "))
Expand All @@ -106,6 +123,8 @@ class TestReleaseManifestCommitLock extends BuildPipelineTest {
@Test
public void testMatchBuildManifest() {
addParam('MANIFEST_LOCK_ACTION', 'MATCH_BUILD_MANIFEST')
addParam('OPENSEARCH_RELEASE_CANDIDATE', '3813')
addParam('OPENSEARCH_DASHBOARDS_RELEASE_CANDIDATE', '3050')
def buildManifest = "tests/jenkins/data/opensearch-2.0.0-build.yml"
helper.registerAllowedMethod('readYaml', [Map.class], { args ->
return new Yaml().load((buildManifest as File).text)
Expand Down

0 comments on commit 1ac678e

Please sign in to comment.