Skip to content

Commit

Permalink
Update the AUTOCUT issues with the latest build fail information (#253
Browse files Browse the repository at this point in the history
)

Signed-off-by: Prudhvi Godithi <[email protected]>
  • Loading branch information
prudhvigodithi authored Jul 27, 2023
1 parent 5b00d67 commit a312326
Show file tree
Hide file tree
Showing 24 changed files with 439 additions and 50 deletions.
2 changes: 1 addition & 1 deletion DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Jenkins workflow regression tests typically output a .txt file into [tests/jenki
For example, [TestHello.groovy](tests/jenkins/TestHello.groovy) executes [Hello_Jenkinsfile](tests/jenkins/jobs/Hello_Jenkinsfile)
and outputs [Hello_Jenkinsfile.txt](tests/jenkins/jobs/Hello_Jenkinsfile.txt). If the job execution changes, the regression test will fail.

- To update the recorded .txt file run `./gradlew test -info -Ppipeline.stack.write=true` or update its value in [gradle.properties](gradle.properties).
- To update the recorded .txt file run `./gradlew test -info -Dpipeline.stack.write=true` or update its value in [gradle.properties](gradle.properties).

- To run a specific test case, run `./gradlew test -info --tests=TestCaseClassName`

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ lib = library(identifier: 'jenkins@<tag>', retriever: modernSCM([
| [publishToNuget.groovy](./vars/publishToNuget.groovy) | A library to build, sign and publish dotnet artifacts to [Nuget Gallery](https://www.nuget.org/). Please check if the [default docker](https://github.com/opensearch-project/opensearch-build/blob/main/docker/ci/dockerfiles/current/release.centos.clients.x64.arm64.dockerfile) file contains the required dotnet sdk. You can use [PublishToNugetLibTester](./tests/jenkins/lib-testers/PublishToNugetLibTester.groovy) to add tests in your repository. See how to use the lib in your [jenkinsFile](./tests/jenkins/jobs/PublishToNuget_Jenkinsfile).
| [publishToArtifactsProdBucket.groovy](./vars/publishToArtifactsProdBucket.groovy) | This library signs and uploads the artifacts to production S3 bucket which points to artifacts.opensearch.org. Please make sure the role that you use to upload exists and has the right permission. For artifacts of different types like macos, linux and windows, call this lib for each artifact with different signing parameters. You can use [PublishToArtifactsProdBucketLibTester](./tests/jenkins/lib-testers/PublishToArtifactsProdBucketLibTester.groovy) to add tests in your repository. See how to use the lib in your [jenkinsFile](./tests/jenkins/jobs/PublishToArtifactsProdBucket_Jenkinsfile).

| [buildMessage.groovy](./vars/buildMessage.groovy) | This library that can parse the jenkins build log based on the user defined input query string.
| [closeBuildSuccessGithubIssue.groovy](./vars/closeBuildSuccessGithubIssue.groovy) | This library that identifies the successfully built components and closes the created [AUTOCUT] issues.
| [createGithubIssue.groovy](./vars/createGithubIssue.groovy) | This library that identifies the failed components and creates the [AUTOCUT] issues.

## Contributing

See [developer guide](DEVELOPER_GUIDE.md) and [how to contribute to this project](CONTRIBUTING.md).
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jacocoTestReport {
}
}

String version = '5.3.0'
String version = '5.4.0'

task updateVersion {
doLast {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ package jenkins.tests
import jenkins.tests.BuildPipelineTest
import org.junit.*

class TestBuildFailureMessage extends BuildPipelineTest {
class TestBuildMessage extends BuildPipelineTest {


@Before
void setUp() {
this.registerLibTester(new BuildFailureMessageLibTester())
this.registerLibTester(new BuildMessageLibTester('pass'))
super.setUp()
def currentBuild = binding.getVariable('currentBuild')
binding.setVariable("currentBuild", currentBuild)
}

@Test
void testBuildFailureMsg() {
super.testPipeline("tests/jenkins/jobs/BuildFailureMessage_Jenkinsfile")
super.testPipeline("tests/jenkins/jobs/BuildMessage_Jenkinsfile")
}
}
46 changes: 46 additions & 0 deletions tests/jenkins/TestCloseBuildSuccessGithubIssue.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package jenkins.tests

import jenkins.tests.BuildPipelineTest
import org.junit.Before
import org.junit.Test
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString
import static org.hamcrest.CoreMatchers.hasItem
import static org.hamcrest.MatcherAssert.assertThat

class TestCloseBuildSuccessGithubIssue extends BuildPipelineTest {

@Override
@Before
void setUp() {
this.registerLibTester(new CloseBuildSuccessGithubIssueLibTester(['Build successful OpenSearch']))
super.setUp()
}


@Test
public void testExistingGithubIssue() {
super.testPipeline('tests/jenkins/jobs/CloseBuildSuccessGithubIssue_JenkinsFile')
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 close bbb\nccc -R opensearch-project/OpenSearch --comment \"Closing the issue as the distribution build for OpenSearch has passed for version: **2.0.0**.\n Please see build log at www.example.com/jobs/test/123/consoleFull\", returnStdout=true}"))
}

def getCommands(method, text) {
def shCommands = helper.callStack.findAll { call ->
call.methodName == method
}.collect { call ->
callArgsToString(call)
}.findAll { command ->
command.contains(text)
}
return shCommands
}

}
51 changes: 51 additions & 0 deletions tests/jenkins/TestCloseGithubIssue.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package jenkins.tests

import jenkins.tests.BuildPipelineTest
import org.junit.Before
import org.junit.Test
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString
import static org.hamcrest.CoreMatchers.hasItem
import static org.hamcrest.MatcherAssert.assertThat

class TestCloseGithubIssue extends BuildPipelineTest {

@Override
@Before
void setUp() {
super.setUp()
}


@Test
void testCloseExistingGithubIssue() {
this.registerLibTester(new CloseGithubIssueLibTester(
'https://github.com/opensearch-project/opensearch-build',
'Test GH issue title',
'Test GH issue close comment',
'label101',
))
super.testPipeline("tests/jenkins/jobs/CloseGithubIssue_JenkinsFile")
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 label101 --json number --jq '.[0].number', returnStdout=true}"))
assertThat(getCommands('sh', 'script'), hasItem("{script=gh issue close bbb\nccc -R opensearch-project/opensearch-build --comment \"Test GH issue close comment\", returnStdout=true}"))
}

def getCommands(method, text) {
def shCommands = helper.callStack.findAll { call ->
call.methodName == method
}.collect { call ->
callArgsToString(call)
}.findAll { command ->
command.contains(text)
}
return shCommands
}

}
5 changes: 4 additions & 1 deletion tests/jenkins/TestCreateBuildFailureGithubIssue.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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 bbb\nccc --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) {
Expand Down
8 changes: 5 additions & 3 deletions tests/jenkins/TestCreateGithubIssue.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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 bbb\nccc --repo https://github.com/opensearch-project/opensearch-build --body \"Test GH issue body\", returnStdout=true}"))
}

def getCommands(method, text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pipeline {
steps {
script {
try {
buildFailureMessage()
buildMessage(search: 'pass')
currentBuild.result = 'SUCCESS'
} catch (Exception err) {
//https://github.com/jenkinsci/JenkinsPipelineUnit/issues/509
Expand Down
6 changes: 6 additions & 0 deletions tests/jenkins/jobs/BuildMessage_Jenkinsfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BuildMessage_Jenkinsfile.run()
BuildMessage_Jenkinsfile.pipeline(groovy.lang.Closure)
BuildMessage_Jenkinsfile.echo(Executing on agent [label:none])
BuildMessage_Jenkinsfile.stage(notify, groovy.lang.Closure)
BuildMessage_Jenkinsfile.script(groovy.lang.Closure)
BuildMessage_Jenkinsfile.buildMessage({search=pass})
24 changes: 24 additions & 0 deletions tests/jenkins/jobs/CloseBuildSuccessGithubIssue_JenkinsFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

pipeline {
agent none
stages {
stage('notify') {
steps {
script {
closeBuildSuccessGithubIssue(
message: ["Build successful OpenSearch"],
inputManifestPath: 'tests/data/opensearch-2.0.0.yml'
)
}
}
}
}
}
18 changes: 18 additions & 0 deletions tests/jenkins/jobs/CloseBuildSuccessGithubIssue_JenkinsFile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CloseBuildSuccessGithubIssue_JenkinsFile.run()
CloseBuildSuccessGithubIssue_JenkinsFile.pipeline(groovy.lang.Closure)
CloseBuildSuccessGithubIssue_JenkinsFile.echo(Executing on agent [label:none])
CloseBuildSuccessGithubIssue_JenkinsFile.stage(notify, groovy.lang.Closure)
CloseBuildSuccessGithubIssue_JenkinsFile.script(groovy.lang.Closure)
CloseBuildSuccessGithubIssue_JenkinsFile.closeBuildSuccessGithubIssue({message=[Build successful OpenSearch], inputManifestPath=tests/data/opensearch-2.0.0.yml})
closeBuildSuccessGithubIssue.legacySCM(groovy.lang.Closure)
closeBuildSuccessGithubIssue.library({identifier=jenkins@main, retriever=null})
closeBuildSuccessGithubIssue.readYaml({file=tests/data/opensearch-2.0.0.yml})
closeBuildSuccessGithubIssue.closeGithubIssue({repoUrl=https://github.com/opensearch-project/OpenSearch.git, issueTitle=[AUTOCUT] Distribution Build Failed for OpenSearch-2.0.0, closeComment=Closing the issue as the distribution build for OpenSearch has passed for version: **2.0.0**.
Please see build log at www.example.com/jobs/test/123/consoleFull, label=autocut,v2.0.0})
closeGithubIssue.usernamePassword({credentialsId=jenkins-github-bot-token, passwordVariable=GITHUB_TOKEN, usernameVariable=GITHUB_USER})
closeGithubIssue.withCredentials([[GITHUB_USER, GITHUB_TOKEN]], groovy.lang.Closure)
closeGithubIssue.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})
closeGithubIssue.sh({script=gh issue close bbb
ccc -R opensearch-project/OpenSearch --comment "Closing the issue as the distribution build for OpenSearch has passed for version: **2.0.0**.
Please see build log at www.example.com/jobs/test/123/consoleFull", returnStdout=true})
closeBuildSuccessGithubIssue.sleep({time=3, unit=SECONDS})
26 changes: 26 additions & 0 deletions tests/jenkins/jobs/CloseGithubIssue_JenkinsFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

pipeline {
agent none
stages {
stage('closeGithubIssue') {
steps {
script {
closeGithubIssue(
repoUrl: 'https://github.com/opensearch-project/opensearch-build',
issueTitle: 'Test GH issue title',
closeComment: 'Test GH issue close comment',
label: 'label101'
)
}
}
}
}
}
11 changes: 11 additions & 0 deletions tests/jenkins/jobs/CloseGithubIssue_JenkinsFile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CloseGithubIssue_JenkinsFile.run()
CloseGithubIssue_JenkinsFile.pipeline(groovy.lang.Closure)
CloseGithubIssue_JenkinsFile.echo(Executing on agent [label:none])
CloseGithubIssue_JenkinsFile.stage(closeGithubIssue, groovy.lang.Closure)
CloseGithubIssue_JenkinsFile.script(groovy.lang.Closure)
CloseGithubIssue_JenkinsFile.closeGithubIssue({repoUrl=https://github.com/opensearch-project/opensearch-build, issueTitle=Test GH issue title, closeComment=Test GH issue close comment, label=label101})
closeGithubIssue.usernamePassword({credentialsId=jenkins-github-bot-token, passwordVariable=GITHUB_TOKEN, usernameVariable=GITHUB_USER})
closeGithubIssue.withCredentials([[GITHUB_USER, GITHUB_TOKEN]], groovy.lang.Closure)
closeGithubIssue.sh({script=gh issue list --repo https://github.com/opensearch-project/opensearch-build -S "Test GH issue title in:title" --label label101 --json number --jq '.[0].number', returnStdout=true})
closeGithubIssue.sh({script=gh issue close bbb
ccc -R opensearch-project/opensearch-build --comment "Test GH issue close comment", returnStdout=true})
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@
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})
5 changes: 4 additions & 1 deletion tests/jenkins/jobs/CreateGithubIssueExisting_JenkinsFile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
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})
31 changes: 0 additions & 31 deletions tests/jenkins/lib-testers/BuildFailureMessageLibTester.groovy

This file was deleted.

Loading

0 comments on commit a312326

Please sign in to comment.