-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add standard release pipeline library (#11)
* Add standard release pipeline library Signed-off-by: Sayali Gaikawad <gaiksaya@amazon.com>
- Loading branch information
Showing
7 changed files
with
169 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
|
||
import jenkins.tests.BuildPipelineTest | ||
import org.junit.Before | ||
import org.junit.Test | ||
import static org.hamcrest.MatcherAssert.assertThat | ||
import static org.hamcrest.CoreMatchers.equalTo | ||
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString | ||
import static org.hamcrest.CoreMatchers.hasItem | ||
|
||
|
||
|
||
class TestStandardReleasePipeline extends BuildPipelineTest { | ||
|
||
@Before | ||
void setUp() { | ||
super.setUp() | ||
} | ||
|
||
@Test | ||
void testStandardReleasePipeline() { | ||
super.testPipeline('tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile') | ||
} | ||
|
||
@Test | ||
void testStandardReleasePipelineWithArgs() { | ||
super.testPipeline('tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile') | ||
} | ||
|
||
@Test | ||
void 'check override values'() { | ||
runScript("tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile") | ||
def echoCommand = getEchoCommands().findAll{ | ||
command -> command.contains('agent') | ||
} | ||
|
||
assertThat(echoCommand.size(), equalTo(1)) | ||
assertThat(echoCommand, hasItem('Executing on agent [docker:[image:test:image, reuseNode:false, stages:[:], args:, alwaysPull:true, containerPerStageRoot:false, label:AL2-X64]]')) | ||
} | ||
|
||
@Test | ||
void 'check default values'(){ | ||
runScript("tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile") | ||
def echoCommand = getEchoCommands().findAll{ | ||
command -> command.contains('agent') | ||
} | ||
|
||
assertThat(echoCommand.size(), equalTo(1)) | ||
assertThat(echoCommand, hasItem('Executing on agent [docker:[image:opensearchstaging/ci-runner:release-centos7-clients-v1, reuseNode:false, stages:[:], args:, alwaysPull:true, containerPerStageRoot:false, label:Jenkins-Agent-AL2-X64-C54xlarge-Docker-Host]]')) | ||
} | ||
|
||
def getEchoCommands() { | ||
def echoCommands = helper.callStack.findAll { call -> | ||
call.methodName == 'echo' | ||
}.collect { call -> | ||
callArgsToString(call) | ||
} | ||
return echoCommands | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/jenkins/jobs/StandardReleasePipelineWithArgs_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
standardReleasePipeline(overrideAgent: 'AL2-X64', | ||
overrideDockerImage: 'test:image') | ||
{ | ||
fakePublishToMaven( | ||
mavenArtifactsPath: "/maven", | ||
autoPublish: true | ||
) | ||
} | ||
|
||
def fakePublishToMaven(Map args) { | ||
echo "fakePublishToMaven ${args}" | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile.txt
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,12 @@ | ||
StandardReleasePipelineWithArgs_JenkinsFile.run() | ||
StandardReleasePipelineWithArgs_JenkinsFile.standardReleasePipeline({overrideAgent=AL2-X64, overrideDockerImage=test:image}, groovy.lang.Closure) | ||
standardReleasePipeline.pipeline(groovy.lang.Closure) | ||
standardReleasePipeline.timeout({time=1, unit=HOURS}) | ||
standardReleasePipeline.echo(Executing on agent [docker:[image:test:image, reuseNode:false, stages:[:], args:, alwaysPull:true, containerPerStageRoot:false, label:AL2-X64]]) | ||
standardReleasePipeline.stage(Release, groovy.lang.Closure) | ||
standardReleasePipeline.script(groovy.lang.Closure) | ||
StandardReleasePipelineWithArgs_JenkinsFile.echo(fakePublishToMaven [mavenArtifactsPath:/maven, autoPublish:true]) | ||
standardReleasePipeline.script(groovy.lang.Closure) | ||
standardReleasePipeline.postCleanup() | ||
postCleanup.cleanWs({disableDeferredWipeout=true, deleteDirs=true}) | ||
standardReleasePipeline.sh(docker image prune -f --all) |
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,11 @@ | ||
standardReleasePipeline() | ||
{ | ||
fakePublishToMaven( | ||
mavenArtifactsPath: "/maven", | ||
autoPublish: true | ||
) | ||
} | ||
|
||
def fakePublishToMaven(Map args) { | ||
echo "fakePublishToMaven ${args}" | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile.txt
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,12 @@ | ||
StandardReleasePipeline_JenkinsFile.run() | ||
StandardReleasePipeline_JenkinsFile.standardReleasePipeline(groovy.lang.Closure) | ||
standardReleasePipeline.pipeline(groovy.lang.Closure) | ||
standardReleasePipeline.timeout({time=1, unit=HOURS}) | ||
standardReleasePipeline.echo(Executing on agent [docker:[image:opensearchstaging/ci-runner:release-centos7-clients-v1, reuseNode:false, stages:[:], args:, alwaysPull:true, containerPerStageRoot:false, label:Jenkins-Agent-AL2-X64-C54xlarge-Docker-Host]]) | ||
standardReleasePipeline.stage(Release, groovy.lang.Closure) | ||
standardReleasePipeline.script(groovy.lang.Closure) | ||
StandardReleasePipeline_JenkinsFile.echo(fakePublishToMaven [mavenArtifactsPath:/maven, autoPublish:true]) | ||
standardReleasePipeline.script(groovy.lang.Closure) | ||
standardReleasePipeline.postCleanup() | ||
postCleanup.cleanWs({disableDeferredWipeout=true, deleteDirs=true}) | ||
standardReleasePipeline.sh(docker image prune -f --all) |
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,48 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** A standard release pipeline for OpenSearch projects | ||
@param Map args = [:] args A map of the following parameters | ||
@param body <Required> - A closure containing release steps to be executed in release stage. | ||
@param args.overrideAgent <Optional> - Jenkins agent label to override the default. | ||
@param args.overrideDockerImage <Optional> - Docker image to override the default. | ||
*/ | ||
|
||
void call(Map args = [:], Closure body) { | ||
pipeline { | ||
agent | ||
{ | ||
docker { | ||
label args.overrideAgent ?: 'Jenkins-Agent-AL2-X64-C54xlarge-Docker-Host' | ||
image args.overrideDockerImage ?: 'opensearchstaging/ci-runner:release-centos7-clients-v1' | ||
alwaysPull true | ||
} | ||
} | ||
options { | ||
timeout(time: 1, unit: 'HOURS') | ||
} | ||
stages{ | ||
stage("Release") { | ||
steps { | ||
script { | ||
body() | ||
} | ||
} | ||
} | ||
} | ||
post { | ||
always { | ||
script { | ||
postCleanup() | ||
sh 'docker image prune -f --all' | ||
} | ||
} | ||
} | ||
} | ||
} |