From 17fa91bec505e362b3b43802d6a5c28b753a56ed Mon Sep 17 00:00:00 2001 From: Owais Kazi Date: Tue, 18 Oct 2022 17:45:21 -0700 Subject: [PATCH 1/9] Added precision for codecov (#17) * Added precision for codecov Signed-off-by: Owais Kazi --- .codecov.yml | 6 +++++- MAINTAINERS.md | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.codecov.yml b/.codecov.yml index 465c91eaf..ccd67751e 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -1,6 +1,10 @@ --- coverage: + precision: 2 + round: down + range: '70...90' status: project: default: - target: 98% + target: auto + threshold: 0.2% diff --git a/MAINTAINERS.md b/MAINTAINERS.md index 585b19c53..926c0b6a3 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -8,7 +8,7 @@ | ---------------- | --------------------------------------------------- | ----------- | | Peter Zhu | [peterzhuamazon](https://github.com/peterzhuamazon) | Amazon | | Sayali Gaikawad | [gaiksaya](https://github.com/gaiksaya) | Amazon | -| Prudhvi Godithi | [prudhvigodithi](https://github.com/prudhvigodithi) | Amazon | +| Prudhvi Godithi | [prudhvigodithi](https://github.com/prudhvigodithi) | Amazon | [This document](https://github.com/opensearch-project/.github/blob/main/MAINTAINERS.md) explains what maintainers do in this repo, and how they should be doing it. If you're interested in contributing, see [CONTRIBUTING](CONTRIBUTING.md). From b251fcf658c8c71de13085fd6bb03608801d7ef1 Mon Sep 17 00:00:00 2001 From: Sayali Gaikawad <61760125+gaiksaya@users.noreply.github.com> Date: Wed, 19 Oct 2022 15:52:41 -0700 Subject: [PATCH 2/9] Add standard release pipeline library (#11) * Add standard release pipeline library Signed-off-by: Sayali Gaikawad --- README.md | 6 ++ .../TestStandardReleasePipeline.groovy | 68 +++++++++++++++++++ ...tandardReleasePipelineWithArgs_JenkinsFile | 12 ++++ ...ardReleasePipelineWithArgs_JenkinsFile.txt | 12 ++++ .../jobs/StandardReleasePipeline_JenkinsFile | 11 +++ .../StandardReleasePipeline_JenkinsFile.txt | 12 ++++ vars/standardReleasePipeline.groovy | 48 +++++++++++++ 7 files changed, 169 insertions(+) create mode 100644 tests/jenkins/TestStandardReleasePipeline.groovy create mode 100644 tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile create mode 100644 tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile.txt create mode 100644 tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile create mode 100644 tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile.txt create mode 100644 vars/standardReleasePipeline.groovy diff --git a/README.md b/README.md index 4376c4eed..de6fc4ad5 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,12 @@ lib = library(identifier: 'jenkins@', retriever: modernSCM([ ])) ``` +#### Library Details + +| Name | Description | +|--------------------------------------------------------|:-----------------------------------------------------------------------------------------| +| [standardReleasePipeline.groovy](./vars/standardReleasePipeline.groovy) | The library sets up the necessary jenkins properties for you such as agent label, docker image to use as well as workflow time out. Check how to use the [default](./tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile) in your workflow and how to [overide](./tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile) agent & docker image if you need.| + ## Contributing See [developer guide](DEVELOPER_GUIDE.md) and [how to contribute to this project](CONTRIBUTING.md). diff --git a/tests/jenkins/TestStandardReleasePipeline.groovy b/tests/jenkins/TestStandardReleasePipeline.groovy new file mode 100644 index 000000000..6f0fdfa6a --- /dev/null +++ b/tests/jenkins/TestStandardReleasePipeline.groovy @@ -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 + } +} diff --git a/tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile b/tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile new file mode 100644 index 000000000..4cb1bbec8 --- /dev/null +++ b/tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile @@ -0,0 +1,12 @@ +standardReleasePipeline(overrideAgent: 'AL2-X64', + overrideDockerImage: 'test:image') +{ + fakePublishToMaven( + mavenArtifactsPath: "/maven", + autoPublish: true + ) +} + +def fakePublishToMaven(Map args) { + echo "fakePublishToMaven ${args}" +} \ No newline at end of file diff --git a/tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile.txt b/tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile.txt new file mode 100644 index 000000000..b30fd1ff1 --- /dev/null +++ b/tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile.txt @@ -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) diff --git a/tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile b/tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile new file mode 100644 index 000000000..0291aaffe --- /dev/null +++ b/tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile @@ -0,0 +1,11 @@ +standardReleasePipeline() +{ + fakePublishToMaven( + mavenArtifactsPath: "/maven", + autoPublish: true + ) +} + +def fakePublishToMaven(Map args) { + echo "fakePublishToMaven ${args}" +} \ No newline at end of file diff --git a/tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile.txt b/tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile.txt new file mode 100644 index 000000000..a44747eed --- /dev/null +++ b/tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile.txt @@ -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) diff --git a/vars/standardReleasePipeline.groovy b/vars/standardReleasePipeline.groovy new file mode 100644 index 000000000..5e8390dad --- /dev/null +++ b/vars/standardReleasePipeline.groovy @@ -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 - A closure containing release steps to be executed in release stage. +@param args.overrideAgent - Jenkins agent label to override the default. +@param args.overrideDockerImage - 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' + } + } + } + } + } \ No newline at end of file From ab9432715573bbc1f7338673c816151bb7d4b089 Mon Sep 17 00:00:00 2001 From: Sayali Gaikawad <61760125+gaiksaya@users.noreply.github.com> Date: Thu, 27 Oct 2022 16:52:47 -0700 Subject: [PATCH 3/9] Create publishToNpm library (#21) * Add npm publishing lib Signed-off-by: Sayali Gaikawad --- tests/jenkins/TestPublishToNpm.groovy | 53 +++++++++++++++++++ tests/jenkins/jobs/PublishToNpm_Jenkinsfile | 24 +++++++++ .../jenkins/jobs/PublishToNpm_Jenkinsfile.txt | 10 ++++ ...ardReleasePipelineWithArgs_JenkinsFile.txt | 1 - .../StandardReleasePipeline_JenkinsFile.txt | 1 - .../lib-testers/PublishToNpmLibTester.groovy | 42 +++++++++++++++ vars/publishToNpm.groovy | 22 ++++++++ vars/standardReleasePipeline.groovy | 1 - 8 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 tests/jenkins/TestPublishToNpm.groovy create mode 100644 tests/jenkins/jobs/PublishToNpm_Jenkinsfile create mode 100644 tests/jenkins/jobs/PublishToNpm_Jenkinsfile.txt create mode 100644 tests/jenkins/lib-testers/PublishToNpmLibTester.groovy create mode 100644 vars/publishToNpm.groovy diff --git a/tests/jenkins/TestPublishToNpm.groovy b/tests/jenkins/TestPublishToNpm.groovy new file mode 100644 index 000000000..8d90a7f6e --- /dev/null +++ b/tests/jenkins/TestPublishToNpm.groovy @@ -0,0 +1,53 @@ +/* + * 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 static com.lesfurets.jenkins.unit.MethodCall.callArgsToString +import static org.hamcrest.CoreMatchers.hasItem +import static org.hamcrest.MatcherAssert.assertThat +import org.junit.Before +import org.junit.Test + +class TestPublishToNpm extends BuildPipelineTest { + @Override + @Before + void setUp() { + + this.registerLibTester(new PublishToNpmLibTester('https://github.com/opensearch-project/opensearch-ci', '1.0.0')) + super.setUp() + } + + @Test + public void test() { + super.testPipeline("tests/jenkins/jobs/PublishToNpm_Jenkinsfile") + } + + @Test + void 'verify shell commands'(){ + runScript('tests/jenkins/jobs/PublishToNpm_Jenkinsfile') + + def npmCommands = getShellCommands() + assertThat(npmCommands, hasItem( + 'npm set registry "https://registry.npmjs.org"; npm set //registry.npmjs.org/:_authToken NPM_TOKEN; npm publish --dry-run && npm publish --access public'.toString() + )) + + } + def getShellCommands() { + def shCommands = helper.callStack.findAll { call -> + call.methodName == 'sh' + }.collect { call -> + callArgsToString(call) + }.findAll { npmCommand -> + npmCommand.contains('npm') + } + return shCommands + } +} diff --git a/tests/jenkins/jobs/PublishToNpm_Jenkinsfile b/tests/jenkins/jobs/PublishToNpm_Jenkinsfile new file mode 100644 index 000000000..e75fc8713 --- /dev/null +++ b/tests/jenkins/jobs/PublishToNpm_Jenkinsfile @@ -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('publishToNpm') { + steps { + script { + publishToNpm( + repository: 'https://github.com/opensearch-project/opensearch-ci', + tag: '1.0.0' + ) + } + } + } + } +} diff --git a/tests/jenkins/jobs/PublishToNpm_Jenkinsfile.txt b/tests/jenkins/jobs/PublishToNpm_Jenkinsfile.txt new file mode 100644 index 000000000..4b072a9cc --- /dev/null +++ b/tests/jenkins/jobs/PublishToNpm_Jenkinsfile.txt @@ -0,0 +1,10 @@ + PublishToNpm_Jenkinsfile.run() + PublishToNpm_Jenkinsfile.pipeline(groovy.lang.Closure) + PublishToNpm_Jenkinsfile.echo(Executing on agent [label:none]) + PublishToNpm_Jenkinsfile.stage(publishToNpm, groovy.lang.Closure) + PublishToNpm_Jenkinsfile.script(groovy.lang.Closure) + PublishToNpm_Jenkinsfile.publishToNpm({repository=https://github.com/opensearch-project/opensearch-ci, tag=1.0.0}) + publishToNpm.checkout({$class=GitSCM, branches=[{name=1.0.0}], userRemoteConfigs=[{url=https://github.com/opensearch-project/opensearch-ci}]}) + publishToNpm.string({credentialsId=publish-to-npm-token, variable=NPM_TOKEN}) + publishToNpm.withCredentials([NPM_TOKEN], groovy.lang.Closure) + publishToNpm.sh(npm set registry "https://registry.npmjs.org"; npm set //registry.npmjs.org/:_authToken NPM_TOKEN; npm publish --dry-run && npm publish --access public) diff --git a/tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile.txt b/tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile.txt index b30fd1ff1..33d12b024 100644 --- a/tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile.txt +++ b/tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile.txt @@ -9,4 +9,3 @@ standardReleasePipeline.script(groovy.lang.Closure) standardReleasePipeline.postCleanup() postCleanup.cleanWs({disableDeferredWipeout=true, deleteDirs=true}) - standardReleasePipeline.sh(docker image prune -f --all) diff --git a/tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile.txt b/tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile.txt index a44747eed..9b150c67b 100644 --- a/tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile.txt +++ b/tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile.txt @@ -9,4 +9,3 @@ standardReleasePipeline.script(groovy.lang.Closure) standardReleasePipeline.postCleanup() postCleanup.cleanWs({disableDeferredWipeout=true, deleteDirs=true}) - standardReleasePipeline.sh(docker image prune -f --all) diff --git a/tests/jenkins/lib-testers/PublishToNpmLibTester.groovy b/tests/jenkins/lib-testers/PublishToNpmLibTester.groovy new file mode 100644 index 000000000..c4581f6f3 --- /dev/null +++ b/tests/jenkins/lib-testers/PublishToNpmLibTester.groovy @@ -0,0 +1,42 @@ +/* + * 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 static org.hamcrest.CoreMatchers.notNullValue +import static org.hamcrest.MatcherAssert.assertThat + +class PublishToNpmLibTester extends LibFunctionTester { + + private String repository + private String tag + + public PublishToNpmLibTester(repository, tag){ + this.repository = repository + this.tag = tag + } + + void configure(helper, binding){ + helper.registerAllowedMethod("checkout", [Map], {}) + helper.registerAllowedMethod("withCredentials", [Map, Closure], { args, closure -> + closure.delegate = delegate + return helper.callClosure(closure) + }) + } + void parameterInvariantsAssertions(call){ + assertThat(call.args.repository.first(), notNullValue()) + assertThat(call.args.tag.first(), notNullValue()) + } + + boolean expectedParametersMatcher(call) { + return call.args.repository.first().toString().equals(this.repository) + && call.args.tag.first().toString().equals(this.tag) + } + + String libFunctionName(){ + return 'publishToNpm' + } +} \ No newline at end of file diff --git a/vars/publishToNpm.groovy b/vars/publishToNpm.groovy new file mode 100644 index 000000000..a7e0ead6d --- /dev/null +++ b/vars/publishToNpm.groovy @@ -0,0 +1,22 @@ +/* + * 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. + */ + +/** Library to publish artifacts to NPM registry under @opensearch-project namespace +@param Map args = [:] args A map of the following parameters +@param args.repository - Repository to be used to publish the artifact to npm +@param args.tag - Tag reference to be used to publish the artifact +*/ +void call(Map args = [:]) { + + checkout([$class: 'GitSCM', branches: [[name: "${args.tag}" ]], userRemoteConfigs: [[url: "${args.repository}" ]]]) + + withCredentials([string(credentialsId: 'publish-to-npm-token', variable: 'NPM_TOKEN')]){ + sh """npm set registry "https://registry.npmjs.org"; npm set //registry.npmjs.org/:_authToken ${NPM_TOKEN}; npm publish --dry-run && npm publish --access public""" + } +} \ No newline at end of file diff --git a/vars/standardReleasePipeline.groovy b/vars/standardReleasePipeline.groovy index 5e8390dad..171351aa0 100644 --- a/vars/standardReleasePipeline.groovy +++ b/vars/standardReleasePipeline.groovy @@ -40,7 +40,6 @@ void call(Map args = [:], Closure body) { always { script { postCleanup() - sh 'docker image prune -f --all' } } } From b64a7882c6f6fe27e1125dcae68263b2fe21667f Mon Sep 17 00:00:00 2001 From: Sayali Gaikawad <61760125+gaiksaya@users.noreply.github.com> Date: Mon, 31 Oct 2022 12:20:20 -0700 Subject: [PATCH 4/9] Add standard release pipeline library with generic trigger (#22) Signed-off-by: Sayali Gaikawad --- README.md | 2 + .../TestStandardReleasePipeline.groovy | 2 +- ...dReleasePipelineWithGenericTriggers.groovy | 101 ++++++++++++++++++ .../jenkins/jobs/PublishToNpm_Jenkinsfile.txt | 2 +- ...PipelineWithGenericTriggersTag_Jenkinsfile | 14 +++ ...lineWithGenericTriggersTag_Jenkinsfile.txt | 13 +++ ...asePipelineWithGenericTriggers_Jenkinsfile | 15 +++ ...ipelineWithGenericTriggers_Jenkinsfile.txt | 16 +++ vars/publishToNpm.groovy | 2 +- ...rdReleasePipelineWithGenericTrigger.groovy | 80 ++++++++++++++ 10 files changed, 244 insertions(+), 3 deletions(-) create mode 100644 tests/jenkins/TestStandardReleasePipelineWithGenericTriggers.groovy create mode 100644 tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile create mode 100644 tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile.txt create mode 100644 tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile create mode 100644 tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile.txt create mode 100644 vars/standardReleasePipelineWithGenericTrigger.groovy diff --git a/README.md b/README.md index de6fc4ad5..4d73967de 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ lib = library(identifier: 'jenkins@', retriever: modernSCM([ | Name | Description | |--------------------------------------------------------|:-----------------------------------------------------------------------------------------| | [standardReleasePipeline.groovy](./vars/standardReleasePipeline.groovy) | The library sets up the necessary jenkins properties for you such as agent label, docker image to use as well as workflow time out. Check how to use the [default](./tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile) in your workflow and how to [overide](./tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile) agent & docker image if you need.| +| [standardReleasePipelineWithGenericTrigger.groovy](./vars/standardReleasePipelineWithGenericTrigger.groovy) | A standard release pipeline for OpenSearch projects including generic triggers. A tag or a draft release can be used as a trigger using this library. The defaults are all set to trigger via a draft release. If the release is successful, the release can be published by using right params.. Check how to use the [default](./tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile) in your workflow and how to [overide](./tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile) values| +| [publishToNpm.groovy](./vars/publishToNpm.groovy) | A library to publish artifacts to NPM registry under @opensearch-project namespace. You can use [PublishToNpmLibTester](./tests/jenkins/lib-testers/PublishToNpmLibTester.groovy) to add tests in your repository. See how to use the lib in your [jenkinsFile](./tests/jenkins/jobs/PublishToNpm_Jenkinsfile)| ## Contributing diff --git a/tests/jenkins/TestStandardReleasePipeline.groovy b/tests/jenkins/TestStandardReleasePipeline.groovy index 6f0fdfa6a..02f2c5706 100644 --- a/tests/jenkins/TestStandardReleasePipeline.groovy +++ b/tests/jenkins/TestStandardReleasePipeline.groovy @@ -46,7 +46,7 @@ class TestStandardReleasePipeline extends BuildPipelineTest { assertThat(echoCommand, hasItem('Executing on agent [docker:[image:test:image, reuseNode:false, stages:[:], args:, alwaysPull:true, containerPerStageRoot:false, label:AL2-X64]]')) } - @Test + @Test void 'check default values'(){ runScript("tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile") def echoCommand = getEchoCommands().findAll{ diff --git a/tests/jenkins/TestStandardReleasePipelineWithGenericTriggers.groovy b/tests/jenkins/TestStandardReleasePipelineWithGenericTriggers.groovy new file mode 100644 index 000000000..8605ff79c --- /dev/null +++ b/tests/jenkins/TestStandardReleasePipelineWithGenericTriggers.groovy @@ -0,0 +1,101 @@ +/* + * 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 TestStandardReleasePipelineWithGenericTriggers extends BuildPipelineTest { + + @Before + void setUp() { + helper.registerAllowedMethod("GenericTrigger", [Map.class], null) + binding.setVariable('tag', '1.0.0') + binding.setVariable('release_url', 'https://api.github.com/repos/Codertocat/Hello-World/releases/17372790') + super.setUp() + } + + + @Test + void testStandardReleasePipelineWithGenericTriggers() { + super.testPipeline('tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile') + } + + @Test + void testStandardReleasePipelineWithTagTriggers() { + super.testPipeline('tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile') + } + + @Test + void 'validate override values'() { + runScript("tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile") + def echoCommand = getCommands('echo').findAll{ + command -> command.contains('agent') + } + + assertThat(echoCommand.size(), equalTo(1)) + assertThat(echoCommand, hasItem('Executing on agent [docker:[image:centos:7, reuseNode:false, stages:[:], args:, alwaysPull:true, containerPerStageRoot:false, label:AL2-X64]]')) + } + + @Test + void 'validate default triggers'(){ + runScript("tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile") + def cmd = getCommands('GenericTrigger').findAll{ + c -> c.contains('generic') + } + assertThat(cmd.size(), equalTo(1)) + assertThat(cmd, hasItem('{genericVariables=[{key=ref, value=$.release.tag_name}, {key=isDraft, value=$.release.draft}, {key=release_url, value=$.release.url}], tokenCredentialId=opensearch-ci-webhook-trigger-token, causeString=A tag was cut on opensearch-ci repo, printContributedVariables=false, printPostContent=false, regexpFilterText=$isDraft, regexpFilterExpression=true}')) + } + + @Test + void 'validate release is published'(){ + runScript("tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile") + def cmd = getCommands('sh').findAll{ + c -> c.contains('curl') + } + assertThat(cmd.size(), equalTo(1)) + assertThat(cmd, hasItem("curl -X PATCH -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer GIT_TOKEN' https://api.github.com/repos/Codertocat/Hello-World/releases/17372790 -d '{\"tag_name\":\"1.0.0\",\"draft\":false,\"prerelease\":false}'")) + + } + + @Test + void 'use tag as trigger'(){ + runScript("tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile") + def cmd = getCommands('GenericTrigger').findAll{ + c -> c.contains('generic') + } + assertThat(cmd.size(), equalTo(1)) + assertThat(cmd, hasItem('{genericVariables=[{key=ref, value=.ref}, {key=isDraft, value=$.release.draft}, {key=release_url, value=$.release.url}], tokenCredentialId=opensearch-ci-webhook-trigger-token, causeString=A tag was cut on opensearch-ci repo, printContributedVariables=false, printPostContent=false, regexpFilterText=$ref, regexpFilterExpression=^refs/tags/.*}')) + } + + @Test + void 'validate release is not published'(){ + runScript("tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile") + def cmd = getCommands('sh').findAll{ + c -> c.contains('curl') + } + assertThat(cmd.size(), equalTo(0)) + } + + def getCommands(String method) { + def echoCommands = helper.callStack.findAll { call -> + call.methodName == method + }.collect { call -> + callArgsToString(call) + } + return echoCommands + } +} diff --git a/tests/jenkins/jobs/PublishToNpm_Jenkinsfile.txt b/tests/jenkins/jobs/PublishToNpm_Jenkinsfile.txt index 4b072a9cc..61e6dc6d0 100644 --- a/tests/jenkins/jobs/PublishToNpm_Jenkinsfile.txt +++ b/tests/jenkins/jobs/PublishToNpm_Jenkinsfile.txt @@ -5,6 +5,6 @@ PublishToNpm_Jenkinsfile.script(groovy.lang.Closure) PublishToNpm_Jenkinsfile.publishToNpm({repository=https://github.com/opensearch-project/opensearch-ci, tag=1.0.0}) publishToNpm.checkout({$class=GitSCM, branches=[{name=1.0.0}], userRemoteConfigs=[{url=https://github.com/opensearch-project/opensearch-ci}]}) - publishToNpm.string({credentialsId=publish-to-npm-token, variable=NPM_TOKEN}) + publishToNpm.string({credentialsId=jenkins-opensearch-publish-to-npm-token, variable=NPM_TOKEN}) publishToNpm.withCredentials([NPM_TOKEN], groovy.lang.Closure) publishToNpm.sh(npm set registry "https://registry.npmjs.org"; npm set //registry.npmjs.org/:_authToken NPM_TOKEN; npm publish --dry-run && npm publish --access public) diff --git a/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile b/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile new file mode 100644 index 000000000..d1cfe7185 --- /dev/null +++ b/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile @@ -0,0 +1,14 @@ +standardReleasePipelineWithGenericTrigger(jsonValue: '.ref', + tokenIdCredential: 'opensearch-ci-webhook-trigger-token', + causeString: 'A tag was cut on opensearch-ci repo', + regexpFilterText: '$ref', + regexpFilterExpression: '^refs/tags/.*') +{ + fakePublishToNpm( + tag: "${tag}" + ) +} + +def fakePublishToNpm(Map args) { + echo "fakePublishToNpm ${args}" +} \ No newline at end of file diff --git a/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile.txt b/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile.txt new file mode 100644 index 000000000..40054e6f2 --- /dev/null +++ b/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile.txt @@ -0,0 +1,13 @@ + StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile.run() + StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile.standardReleasePipelineWithGenericTrigger({jsonValue=.ref, tokenIdCredential=opensearch-ci-webhook-trigger-token, causeString=A tag was cut on opensearch-ci repo, regexpFilterText=$ref, regexpFilterExpression=^refs/tags/.*}, groovy.lang.Closure) + standardReleasePipelineWithGenericTrigger.pipeline(groovy.lang.Closure) + standardReleasePipelineWithGenericTrigger.timeout({time=1, unit=HOURS}) + standardReleasePipelineWithGenericTrigger.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]]) + standardReleasePipelineWithGenericTrigger.GenericTrigger({genericVariables=[{key=ref, value=.ref}, {key=isDraft, value=$.release.draft}, {key=release_url, value=$.release.url}], tokenCredentialId=opensearch-ci-webhook-trigger-token, causeString=A tag was cut on opensearch-ci repo, printContributedVariables=false, printPostContent=false, regexpFilterText=$ref, regexpFilterExpression=^refs/tags/.*}) + standardReleasePipelineWithGenericTrigger.stage(Release, groovy.lang.Closure) + standardReleasePipelineWithGenericTrigger.script(groovy.lang.Closure) + StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile.echo(fakePublishToNpm [tag:1.0.0]) + standardReleasePipelineWithGenericTrigger.script(groovy.lang.Closure) + standardReleasePipelineWithGenericTrigger.postCleanup() + postCleanup.cleanWs({disableDeferredWipeout=true, deleteDirs=true}) + standardReleasePipelineWithGenericTrigger.script(groovy.lang.Closure) diff --git a/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile b/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile new file mode 100644 index 000000000..b2fe4e1ca --- /dev/null +++ b/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile @@ -0,0 +1,15 @@ +standardReleasePipelineWithGenericTrigger(overrideAgent: 'AL2-X64', + overrideDockerImage: 'centos:7', + tokenIdCredential: 'opensearch-ci-webhook-trigger-token', + causeString: 'A tag was cut on opensearch-ci repo', + publishRelease: true) +{ + fakePublishToMaven( + mavenArtifactsPath: "/maven", + autoPublish: true + ) +} + +def fakePublishToMaven(Map args) { + echo "fakePublishToMaven ${args}" +} \ No newline at end of file diff --git a/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile.txt b/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile.txt new file mode 100644 index 000000000..4352967cf --- /dev/null +++ b/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile.txt @@ -0,0 +1,16 @@ + StandardReleasePipelineWithGenericTriggers_Jenkinsfile.run() + StandardReleasePipelineWithGenericTriggers_Jenkinsfile.standardReleasePipelineWithGenericTrigger({overrideAgent=AL2-X64, overrideDockerImage=centos:7, tokenIdCredential=opensearch-ci-webhook-trigger-token, causeString=A tag was cut on opensearch-ci repo, publishRelease=true}, groovy.lang.Closure) + standardReleasePipelineWithGenericTrigger.pipeline(groovy.lang.Closure) + standardReleasePipelineWithGenericTrigger.timeout({time=1, unit=HOURS}) + standardReleasePipelineWithGenericTrigger.echo(Executing on agent [docker:[image:centos:7, reuseNode:false, stages:[:], args:, alwaysPull:true, containerPerStageRoot:false, label:AL2-X64]]) + standardReleasePipelineWithGenericTrigger.GenericTrigger({genericVariables=[{key=ref, value=$.release.tag_name}, {key=isDraft, value=$.release.draft}, {key=release_url, value=$.release.url}], tokenCredentialId=opensearch-ci-webhook-trigger-token, causeString=A tag was cut on opensearch-ci repo, printContributedVariables=false, printPostContent=false, regexpFilterText=$isDraft, regexpFilterExpression=true}) + standardReleasePipelineWithGenericTrigger.stage(Release, groovy.lang.Closure) + standardReleasePipelineWithGenericTrigger.script(groovy.lang.Closure) + StandardReleasePipelineWithGenericTriggers_Jenkinsfile.echo(fakePublishToMaven [mavenArtifactsPath:/maven, autoPublish:true]) + standardReleasePipelineWithGenericTrigger.script(groovy.lang.Closure) + standardReleasePipelineWithGenericTrigger.postCleanup() + postCleanup.cleanWs({disableDeferredWipeout=true, deleteDirs=true}) + standardReleasePipelineWithGenericTrigger.script(groovy.lang.Closure) + standardReleasePipelineWithGenericTrigger.string({credentialsId=jenkins-github-bot-token, variable=GIT_TOKEN}) + standardReleasePipelineWithGenericTrigger.withCredentials([GIT_TOKEN], groovy.lang.Closure) + standardReleasePipelineWithGenericTrigger.sh(curl -X PATCH -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer GIT_TOKEN' https://api.github.com/repos/Codertocat/Hello-World/releases/17372790 -d '{"tag_name":"1.0.0","draft":false,"prerelease":false}') diff --git a/vars/publishToNpm.groovy b/vars/publishToNpm.groovy index a7e0ead6d..9b2ae47c6 100644 --- a/vars/publishToNpm.groovy +++ b/vars/publishToNpm.groovy @@ -16,7 +16,7 @@ void call(Map args = [:]) { checkout([$class: 'GitSCM', branches: [[name: "${args.tag}" ]], userRemoteConfigs: [[url: "${args.repository}" ]]]) - withCredentials([string(credentialsId: 'publish-to-npm-token', variable: 'NPM_TOKEN')]){ + withCredentials([string(credentialsId: 'jenkins-opensearch-publish-to-npm-token', variable: 'NPM_TOKEN')]){ sh """npm set registry "https://registry.npmjs.org"; npm set //registry.npmjs.org/:_authToken ${NPM_TOKEN}; npm publish --dry-run && npm publish --access public""" } } \ No newline at end of file diff --git a/vars/standardReleasePipelineWithGenericTrigger.groovy b/vars/standardReleasePipelineWithGenericTrigger.groovy new file mode 100644 index 000000000..d04a2bbe1 --- /dev/null +++ b/vars/standardReleasePipelineWithGenericTrigger.groovy @@ -0,0 +1,80 @@ +/* + * 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 including generic triggers. A tag or a draft release can be used as a trigger using this library. The defaults are all set to trigger via a draft release. If the release is successful, the release can be published by using right params. +@param Map args = [:] args A map of the following parameters +@param body - A closure containing release steps to be executed in release stage. +@param args.tokenIdCredential - Credential id containing token for trigger authentication +@param args.overrideAgent - Jenkins agent label to override the default ('Jenkins-Agent-AL2-X64-C54xlarge-Docker-Host') +@param args.overrideDockerImage - Docker image to override the default ('opensearchstaging/ci-runner:release-centos7-clients-v1') +@param args.jsonValue - Json value retrieved from payload of the webhook. Defaults to '$.release.tag_name' +@param args.causeString - String mentioning why the workflow was triggered. Defaults to 'A tag was cut on GitHub repository causing this workflow to run' +@param args.regexpFilterText - Variable to apply regular expression on. Defaults to '$isDraft' +@param.regexpFilterExpression - Regular expression to test on the evaluated text specified. Defaults to '' +@param.publishRelease - If set to true the release that triggered the job will be published on GitHub. +*/ + +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') + } + triggers { + GenericTrigger( + genericVariables: [ + [key: 'ref', value: (args.jsonValue ?: '$.release.tag_name')], + [key: 'isDraft', value: '$.release.draft'], + [key: 'release_url', value: '$.release.url'] + ], + tokenCredentialId: args.tokenIdCredential, + causeString: args.causeString ?: 'A tag was cut on GitHub repository causing this workflow to run', + printContributedVariables: false, + printPostContent: false, + regexpFilterText: (args.regexpFilterText ?: '$isDraft'), + regexpFilterExpression: (args.regexpFilterExpression ?: 'true') + ) + } + environment { + tag = "$ref" + } + stages{ + stage("Release") { + steps { + script { + body() + } + } + } + } + post { + success { + script { + if (args.publishRelease && release_url!= null){ + withCredentials([string(credentialsId: 'jenkins-github-bot-token', variable: 'GIT_TOKEN')]){ + sh "curl -X PATCH -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer ${GIT_TOKEN}' ${release_url} -d '{\"tag_name\":\"${tag}\",\"draft\":false,\"prerelease\":false}'" + } + } + } + } + always { + script { + postCleanup() + } + } + } + } + } \ No newline at end of file From aee18fdf942ec4bee7ce8093a8ab1ed689f8c79a Mon Sep 17 00:00:00 2001 From: Sayali Gaikawad <61760125+gaiksaya@users.noreply.github.com> Date: Mon, 31 Oct 2022 15:43:14 -0700 Subject: [PATCH 5/9] Add release workflow and readme (#23) * Add release.yml Signed-off-by: Sayali Gaikawad --- .github/workflows/release.yml | 18 ++++++++++++++++++ RELEASING.md | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 RELEASING.md diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..029bde77c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,18 @@ +--- +name: Create a release + +on: + push: + tags: + - '*' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Release + uses: softprops/action-gh-release@v1 + with: + generate_release_notes: true diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 000000000..4a34aaea3 --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,19 @@ +- [Overview](#overview) +- [Versioning](#versioning) +- [Releasing](#releasing) + +## Overview + +This document explains the release strategy for artifacts in this organization. + +## Versioning + +This respository, as other in this organization follows semantic versioning. + +- **major**: Breaking changes +- **minor**: New features +- **patch**: Bug fixes + +## Releasing + +The release process includes a [MAINTAINER](MAINTAINERS.md) pushing a tag to this repository. \ No newline at end of file From ecf3db793df811f95e609c3cfd9183314c37dbd3 Mon Sep 17 00:00:00 2001 From: Sayali Gaikawad <61760125+gaiksaya@users.noreply.github.com> Date: Tue, 1 Nov 2022 15:02:18 -0700 Subject: [PATCH 6/9] Fix releasing.md (#25) Signed-off-by: Sayali Gaikawad Signed-off-by: Sayali Gaikawad --- RELEASING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASING.md b/RELEASING.md index 4a34aaea3..4f234e470 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -16,4 +16,4 @@ This respository, as other in this organization follows semantic versioning. ## Releasing -The release process includes a [MAINTAINER](MAINTAINERS.md) pushing a tag to this repository. \ No newline at end of file +The release process includes a [maintainer](MAINTAINERS.md) pushing a tag to this repository which creates a release on GitHub via [release.yml](./.github/workflows/release.yml) workflow. \ No newline at end of file From 0dc9a8341b9084cfbfc7100668f6548e2248d46b Mon Sep 17 00:00:00 2001 From: Sayali Gaikawad <61760125+gaiksaya@users.noreply.github.com> Date: Tue, 1 Nov 2022 17:57:44 -0700 Subject: [PATCH 7/9] Fix credential type for github bot (#26) * Fix credential type for github bot Signed-off-by: Sayali Gaikawad --- ...dReleasePipelineWithGenericTriggers.groovy | 2 +- ...ipelineWithGenericTriggers_Jenkinsfile.txt | 6 ++--- ...rdReleasePipelineWithGenericTrigger.groovy | 24 +++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/jenkins/TestStandardReleasePipelineWithGenericTriggers.groovy b/tests/jenkins/TestStandardReleasePipelineWithGenericTriggers.groovy index 8605ff79c..bab2c86d2 100644 --- a/tests/jenkins/TestStandardReleasePipelineWithGenericTriggers.groovy +++ b/tests/jenkins/TestStandardReleasePipelineWithGenericTriggers.groovy @@ -67,7 +67,7 @@ class TestStandardReleasePipelineWithGenericTriggers extends BuildPipelineTest { c -> c.contains('curl') } assertThat(cmd.size(), equalTo(1)) - assertThat(cmd, hasItem("curl -X PATCH -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer GIT_TOKEN' https://api.github.com/repos/Codertocat/Hello-World/releases/17372790 -d '{\"tag_name\":\"1.0.0\",\"draft\":false,\"prerelease\":false}'")) + assertThat(cmd, hasItem("curl -X PATCH -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer GITHUB_TOKEN' https://api.github.com/repos/Codertocat/Hello-World/releases/17372790 -d '{\"tag_name\":\"1.0.0\",\"draft\":false,\"prerelease\":false}'")) } diff --git a/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile.txt b/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile.txt index 4352967cf..e4e9b5776 100644 --- a/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile.txt +++ b/tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile.txt @@ -11,6 +11,6 @@ standardReleasePipelineWithGenericTrigger.postCleanup() postCleanup.cleanWs({disableDeferredWipeout=true, deleteDirs=true}) standardReleasePipelineWithGenericTrigger.script(groovy.lang.Closure) - standardReleasePipelineWithGenericTrigger.string({credentialsId=jenkins-github-bot-token, variable=GIT_TOKEN}) - standardReleasePipelineWithGenericTrigger.withCredentials([GIT_TOKEN], groovy.lang.Closure) - standardReleasePipelineWithGenericTrigger.sh(curl -X PATCH -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer GIT_TOKEN' https://api.github.com/repos/Codertocat/Hello-World/releases/17372790 -d '{"tag_name":"1.0.0","draft":false,"prerelease":false}') + standardReleasePipelineWithGenericTrigger.usernamePassword({credentialsId=jenkins-github-bot-token, usernameVariable=GITHUB_USER, passwordVariable=GITHUB_TOKEN}) + standardReleasePipelineWithGenericTrigger.withCredentials([[GITHUB_USER, GITHUB_TOKEN]], groovy.lang.Closure) + standardReleasePipelineWithGenericTrigger.sh(curl -X PATCH -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer GITHUB_TOKEN' https://api.github.com/repos/Codertocat/Hello-World/releases/17372790 -d '{"tag_name":"1.0.0","draft":false,"prerelease":false}') diff --git a/vars/standardReleasePipelineWithGenericTrigger.groovy b/vars/standardReleasePipelineWithGenericTrigger.groovy index d04a2bbe1..7ddf83b31 100644 --- a/vars/standardReleasePipelineWithGenericTrigger.groovy +++ b/vars/standardReleasePipelineWithGenericTrigger.groovy @@ -48,11 +48,11 @@ void call(Map args = [:], Closure body) { regexpFilterExpression: (args.regexpFilterExpression ?: 'true') ) } - environment { - tag = "$ref" - } - stages{ - stage("Release") { + environment { + tag = "$ref" + } + stages { + stage('Release') { steps { script { body() @@ -63,18 +63,18 @@ void call(Map args = [:], Closure body) { post { success { script { - if (args.publishRelease && release_url!= null){ - withCredentials([string(credentialsId: 'jenkins-github-bot-token', variable: 'GIT_TOKEN')]){ - sh "curl -X PATCH -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer ${GIT_TOKEN}' ${release_url} -d '{\"tag_name\":\"${tag}\",\"draft\":false,\"prerelease\":false}'" - } - } + if (args.publishRelease && release_url != null) { + withCredentials([usernamePassword(credentialsId: 'jenkins-github-bot-token', usernameVariable: 'GITHUB_USER', passwordVariable: 'GITHUB_TOKEN')]) { + sh "curl -X PATCH -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer ${GITHUB_TOKEN}' ${release_url} -d '{\"tag_name\":\"${tag}\",\"draft\":false,\"prerelease\":false}'" + } + } } } always { script { postCleanup() - } } } } - } \ No newline at end of file + } +} \ No newline at end of file From cd10eb5e8fa3683981d417f55b38e00111b2236d Mon Sep 17 00:00:00 2001 From: Rishabh Singh Date: Wed, 2 Nov 2022 15:22:39 -0700 Subject: [PATCH 8/9] Add untriaged label to new github issues (#27) Signed-off-by: Rishabh Singh Signed-off-by: Rishabh Singh --- vars/createGithubIssue.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/createGithubIssue.groovy b/vars/createGithubIssue.groovy index b0df06492..321b2aa6a 100644 --- a/vars/createGithubIssue.groovy +++ b/vars/createGithubIssue.groovy @@ -64,7 +64,7 @@ def create_issue(component, url, currentVersion, failedMessage){ println("Issue already exists in the repository, skipping.") } else { sh ( - script: "gh issue create --title \"[AUTOCUT] OS Distribution Build Failed for ${component}-${currentVersion}\" --body \"${message}\" --label ${label} --repo ${url}", + script: "gh issue create --title \"[AUTOCUT] OS Distribution Build Failed for ${component}-${currentVersion}\" --body \"${message}\" --label ${label} --label \"untriaged\" --repo ${url}", returnStdout: true ) } From 8c4a6620ce6cb056839a370e0873e17ee4184ab6 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Sat, 5 Nov 2022 01:04:07 -0400 Subject: [PATCH 9/9] Remove docker check for windows gradle check (#28) * Remove docker check for windows gradle check Signed-off-by: Peter Zhu * add test results Signed-off-by: Peter Zhu Signed-off-by: Peter Zhu --- .../jobs/RunGradleCheck_Jenkinsfile.txt | 18 +++++++++-------- vars/runGradleCheck.groovy | 20 ++++++++++--------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/tests/jenkins/jobs/RunGradleCheck_Jenkinsfile.txt b/tests/jenkins/jobs/RunGradleCheck_Jenkinsfile.txt index 12e9722ad..e20675cdf 100644 --- a/tests/jenkins/jobs/RunGradleCheck_Jenkinsfile.txt +++ b/tests/jenkins/jobs/RunGradleCheck_Jenkinsfile.txt @@ -37,15 +37,17 @@ ./gradlew --stop rm -rf ~/.gradle - echo "Check existing dockercontainer" - docker ps -a - docker stop `docker ps -qa` > /dev/null 2>&1 || echo - docker rm `docker ps -qa` > /dev/null 2>&1 || echo - echo "Stop existing dockercontainer" - docker ps -a + if ! (uname -s | grep -i NT); then + echo "Check existing dockercontainer" + docker ps -a + docker stop `docker ps -qa` > /dev/null 2>&1 || echo + docker rm `docker ps -qa` > /dev/null 2>&1 || echo + echo "Stop existing dockercontainer" + docker ps -a - echo "Check docker-compose version" - docker-compose version + echo "Check docker-compose version" + docker-compose version + fi echo "Check existing processes" ps -ef | grep [o]pensearch | wc -l diff --git a/vars/runGradleCheck.groovy b/vars/runGradleCheck.groovy index df95adab2..533c13ae3 100644 --- a/vars/runGradleCheck.groovy +++ b/vars/runGradleCheck.groovy @@ -51,15 +51,17 @@ void call(Map args = [:]) { ./gradlew --stop rm -rf ~/.gradle - echo "Check existing dockercontainer" - docker ps -a - docker stop `docker ps -qa` > /dev/null 2>&1 || echo - docker rm `docker ps -qa` > /dev/null 2>&1 || echo - echo "Stop existing dockercontainer" - docker ps -a - - echo "Check docker-compose version" - docker-compose version + if ! (uname -s | grep -i NT); then + echo "Check existing dockercontainer" + docker ps -a + docker stop `docker ps -qa` > /dev/null 2>&1 || echo + docker rm `docker ps -qa` > /dev/null 2>&1 || echo + echo "Stop existing dockercontainer" + docker ps -a + + echo "Check docker-compose version" + docker-compose version + fi echo "Check existing processes" ps -ef | grep [o]pensearch | wc -l