diff --git a/build.gradle b/build.gradle index e08f82525..3a9d1f6dd 100644 --- a/build.gradle +++ b/build.gradle @@ -120,7 +120,7 @@ jacocoTestReport { } } -String version = '5.2.0' +String version = '5.3.0' task updateVersion { doLast { diff --git a/tests/jenkins/TestCreateBuildFailureGithubIssue.groovy b/tests/jenkins/TestCreateBuildFailureGithubIssue.groovy index fe1dfc0aa..695e7f2e3 100644 --- a/tests/jenkins/TestCreateBuildFailureGithubIssue.groovy +++ b/tests/jenkins/TestCreateBuildFailureGithubIssue.groovy @@ -34,7 +34,10 @@ class TestCreateBuildFailureGithubIssue extends BuildPipelineTest { @Test public void testExistingGithubIssue() { super.testPipeline('tests/jenkins/jobs/CreateBuildFailureGithubIssue_Jenkinsfile', 'tests/jenkins/jobs/CreateBuildFailureGithubExistingIssueCheck_Jenkinsfile') - assertThat(getCommands('println', ''), hasItem('Issue already exists in the repository, skipping.')) + assertThat(getCommands('println', ''), hasItem('Issue already exists, adding a comment.')) + assertThat(getCommands('sh', 'script'), hasItem("{script=gh issue list --repo https://github.com/opensearch-project/OpenSearch.git -S \"[AUTOCUT] Distribution Build Failed for OpenSearch-2.0.0 in:title\" --label autocut,v2.0.0, returnStdout=true}")) + assertThat(getCommands('sh', 'script'), hasItem("{script=gh issue list --repo https://github.com/opensearch-project/OpenSearch.git -S \"[AUTOCUT] Distribution Build Failed for OpenSearch-2.0.0 in:title\" --label autocut,v2.0.0 --json number --jq '.[0].number', returnStdout=true}")) + assertThat(getCommands('sh', 'script'), hasItem("{script=gh issue comment \nbbb\nccc\n --repo https://github.com/opensearch-project/OpenSearch.git --body \"***Received Error***: **Error building OpenSearch, retry with: ./build.sh manifests/2.2.0/opensearch-2.2.0.yml --component OpenSearch --snapshot**.\n The distribution build for OpenSearch has failed for version: 2.0.0.\n Please see build log at www.example.com/jobs/test/123/consoleFull\", returnStdout=true}")) } def getCommands(method, text) { diff --git a/tests/jenkins/TestCreateGithubIssue.groovy b/tests/jenkins/TestCreateGithubIssue.groovy index c271bc53a..0ff07e110 100644 --- a/tests/jenkins/TestCreateGithubIssue.groovy +++ b/tests/jenkins/TestCreateGithubIssue.groovy @@ -41,11 +41,13 @@ class TestCreateGithubIssue extends BuildPipelineTest { this.registerLibTester(new CreateGithubIssueLibTester( 'https://github.com/opensearch-project/opensearch-build', 'Test GH issue title', - 'Test GH issue body' + 'Test GH issue body', )) super.testPipeline('tests/jenkins/jobs/CreateGithubIssueExisting_JenkinsFile') - assertThat(getCommands('println', ''), hasItem('Issue already exists in the repository, skipping.')) - assertThat(getCommands('sh', 'script'), hasItem('{script=gh issue list --repo https://github.com/opensearch-project/opensearch-build -S "Test GH issue title in:title" --label autocut, returnStdout=true}')) + assertThat(getCommands('println', ''), hasItem('Issue already exists, adding a comment.')) + assertThat(getCommands('sh', 'script'), hasItem("{script=gh issue list --repo https://github.com/opensearch-project/opensearch-build -S \"Test GH issue title in:title\" --label autocut, returnStdout=true}")) + assertThat(getCommands('sh', 'script'), hasItem("{script=gh issue list --repo https://github.com/opensearch-project/opensearch-build -S \"Test GH issue title in:title\" --label autocut --json number --jq '.[0].number', returnStdout=true}")) + assertThat(getCommands('sh', 'script'), hasItem("{script=gh issue comment \nbbb\nccc\n --repo https://github.com/opensearch-project/opensearch-build --body \"Test GH issue body\", returnStdout=true}")) } def getCommands(method, text) { diff --git a/tests/jenkins/jobs/CreateBuildFailureGithubExistingIssueCheck_Jenkinsfile.txt b/tests/jenkins/jobs/CreateBuildFailureGithubExistingIssueCheck_Jenkinsfile.txt index e19c52fdd..3e7ede57e 100644 --- a/tests/jenkins/jobs/CreateBuildFailureGithubExistingIssueCheck_Jenkinsfile.txt +++ b/tests/jenkins/jobs/CreateBuildFailureGithubExistingIssueCheck_Jenkinsfile.txt @@ -13,5 +13,12 @@ createGithubIssue.usernamePassword({credentialsId=jenkins-github-bot-token, passwordVariable=GITHUB_TOKEN, usernameVariable=GITHUB_USER}) createGithubIssue.withCredentials([[GITHUB_USER, GITHUB_TOKEN]], groovy.lang.Closure) createGithubIssue.sh({script=gh issue list --repo https://github.com/opensearch-project/OpenSearch.git -S "[AUTOCUT] Distribution Build Failed for OpenSearch-2.0.0 in:title" --label autocut,v2.0.0, returnStdout=true}) - createGithubIssue.println(Issue already exists in the repository, skipping.) + createGithubIssue.println(Issue already exists, adding a comment.) + createGithubIssue.sh({script=gh issue list --repo https://github.com/opensearch-project/OpenSearch.git -S "[AUTOCUT] Distribution Build Failed for OpenSearch-2.0.0 in:title" --label autocut,v2.0.0 --json number --jq '.[0].number', returnStdout=true}) + createGithubIssue.sh({script=gh issue comment +bbb +ccc + --repo https://github.com/opensearch-project/OpenSearch.git --body "***Received Error***: **Error building OpenSearch, retry with: ./build.sh manifests/2.2.0/opensearch-2.2.0.yml --component OpenSearch --snapshot**. + The distribution build for OpenSearch has failed for version: 2.0.0. + Please see build log at www.example.com/jobs/test/123/consoleFull", returnStdout=true}) createBuildFailureGithubIssue.sleep({time=3, unit=SECONDS}) diff --git a/tests/jenkins/jobs/CreateGithubIssueExisting_JenkinsFile.txt b/tests/jenkins/jobs/CreateGithubIssueExisting_JenkinsFile.txt index 2589b67a6..852272094 100644 --- a/tests/jenkins/jobs/CreateGithubIssueExisting_JenkinsFile.txt +++ b/tests/jenkins/jobs/CreateGithubIssueExisting_JenkinsFile.txt @@ -7,4 +7,9 @@ createGithubIssue.usernamePassword({credentialsId=jenkins-github-bot-token, passwordVariable=GITHUB_TOKEN, usernameVariable=GITHUB_USER}) createGithubIssue.withCredentials([[GITHUB_USER, GITHUB_TOKEN]], groovy.lang.Closure) createGithubIssue.sh({script=gh issue list --repo https://github.com/opensearch-project/opensearch-build -S "Test GH issue title in:title" --label autocut, returnStdout=true}) - createGithubIssue.println(Issue already exists in the repository, skipping.) + createGithubIssue.println(Issue already exists, adding a comment.) + createGithubIssue.sh({script=gh issue list --repo https://github.com/opensearch-project/opensearch-build -S "Test GH issue title in:title" --label autocut --json number --jq '.[0].number', returnStdout=true}) + createGithubIssue.sh({script=gh issue comment +bbb +ccc + --repo https://github.com/opensearch-project/opensearch-build --body "Test GH issue body", returnStdout=true}) diff --git a/vars/createGithubIssue.groovy b/vars/createGithubIssue.groovy index 2134c357d..5dd48f607 100644 --- a/vars/createGithubIssue.groovy +++ b/vars/createGithubIssue.groovy @@ -24,7 +24,15 @@ void call(Map args = [:]) { ) if (issues) { - println('Issue already exists in the repository, skipping.') + println('Issue already exists, adding a comment.') + def issuesNumber = sh( + script: "gh issue list --repo ${args.repoUrl} -S \"${args.issueTitle} in:title\" --label ${label} --json number --jq '.[0].number'", + returnStdout: true + ) + sh( + script: "gh issue comment ${issuesNumber} --repo ${args.repoUrl} --body \"${args.issueBody}\"", + returnStdout: true + ) } else { sh(