forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added enhancement to slack publish with build failure cause (opensear…
…ch-project#1819) * Added enhancement to slack publish with build failure cause Signed-off-by: pgodithi <[email protected]> * Added Unit tests Signed-off-by: pgodithi <[email protected]> * Added Unit tests Signed-off-by: pgodithi <[email protected]> * Added Unit tests Signed-off-by: pgodithi <[email protected]> * Added Unit tests Signed-off-by: pgodithi <[email protected]> * Added data types Signed-off-by: pgodithi <[email protected]> * Added data types Signed-off-by: pgodithi <[email protected]> * Added data types Signed-off-by: pgodithi <[email protected]> * Added data types Signed-off-by: pgodithi <[email protected]> * Added data types Signed-off-by: pgodithi <[email protected]> * Added data types Signed-off-by: pgodithi <[email protected]> * Added data types Signed-off-by: pgodithi <[email protected]> * Added data types Signed-off-by: pgodithi <[email protected]> * Buffer Reader to store the jenkins log and read from this stream Signed-off-by: pgodithi <[email protected]> * Removed delimiter Signed-off-by: pgodithi <[email protected]> * Removed delimiter Signed-off-by: pgodithi <[email protected]> * Added test files Signed-off-by: pgodithi <[email protected]> * Added jenkins BuildFailureMessage shared lib test cases Signed-off-by: pgodithi <[email protected]> * Fixing all failed test cases Signed-off-by: pgodithi <[email protected]> * Fixing all failed test cases: testing Signed-off-by: pgodithi <[email protected]> * Fixing all failed test cases: testing Signed-off-by: pgodithi <[email protected]> * Fixing double-quotes bug in buildFailureMessage.groovy file Signed-off-by: pgodithi <[email protected]> * Fixing double-quotes bug in buildFailureMessage.groovy file Signed-off-by: pgodithi <[email protected]> * Added buildFailureMessage() pipelines Signed-off-by: pgodithi <[email protected]> * Added buildFailureMessage() pipelines Signed-off-by: pgodithi <[email protected]> * removing buildFailureMessage() for dashboard jenkinsfile Signed-off-by: pgodithi <[email protected]>
- Loading branch information
1 parent
7f58698
commit aa6b829
Showing
14 changed files
with
151 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* 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.* | ||
|
||
class TestBuildFailureMessage extends BuildPipelineTest { | ||
|
||
|
||
@Before | ||
void setUp() { | ||
this.registerLibTester(new BuildFailureMessageLibTester()) | ||
super.setUp() | ||
def currentBuild = binding.getVariable('currentBuild') | ||
binding.setVariable("currentBuild", currentBuild) | ||
} | ||
|
||
@Test | ||
void testBuildFailureMsg() { | ||
super.testPipeline("tests/jenkins/jobs/BuildFailureMessage_Jenkinsfile") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
pipeline { | ||
agent none | ||
stages { | ||
stage('notify') { | ||
steps { | ||
script { | ||
try { | ||
buildFailureMessage() | ||
currentBuild.result = 'SUCCESS' | ||
} catch (Exception err) { | ||
//https://github.com/jenkinsci/JenkinsPipelineUnit/issues/509 | ||
currentBuild.result = 'SUCCESS' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
BuildFailureMessage_Jenkinsfile.run() | ||
BuildFailureMessage_Jenkinsfile.pipeline(groovy.lang.Closure) | ||
BuildFailureMessage_Jenkinsfile.echo(Executing on agent [label:none]) | ||
BuildFailureMessage_Jenkinsfile.stage(notify, groovy.lang.Closure) | ||
BuildFailureMessage_Jenkinsfile.script(groovy.lang.Closure) | ||
BuildFailureMessage_Jenkinsfile.buildFailureMessage() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
tests/jenkins/lib-testers/BuildFailureMessageLibTester.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import static org.hamcrest.CoreMatchers.notNullValue | ||
import static org.hamcrest.MatcherAssert.assertThat | ||
|
||
class BuildFailureMessageLibTester extends LibFunctionTester { | ||
|
||
|
||
public BuildFailureMessageLibTester() {} | ||
|
||
|
||
void parameterInvariantsAssertions(call) { | ||
//N/A | ||
} | ||
|
||
boolean expectedParametersMatcher(call) { | ||
return true | ||
} | ||
|
||
|
||
String libFunctionName() { | ||
return 'buildFailureMessage' | ||
} | ||
|
||
void configure(helper, binding){ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import com.cloudbees.groovy.cps.NonCPS | ||
import org.apache.commons.io.IOUtils | ||
@NonCPS | ||
def call(){ | ||
String ERROR_STRING = "ERROR" | ||
List<String> message = [] | ||
Reader performance_log = currentBuild.getRawBuild().getLogReader() | ||
String logContent = IOUtils.toString(performance_log) | ||
performance_log.close() | ||
performance_log = null | ||
logContent.eachLine() { line -> | ||
if (line.matches(".*?$ERROR_STRING(.*?)")) { | ||
line=line.replace("\"", "") | ||
message.add(line) | ||
} | ||
} | ||
if(message.isEmpty()){ | ||
message=["Build failed"] | ||
} | ||
return message | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters