From a47e26cabcb1abf6d7f364ab8ea3174e4b7996f2 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 20 Nov 2019 14:20:09 +0000 Subject: [PATCH 01/15] Enable opbeans release process align with the agent somehow --- src/test/groovy/ApmBasePipelineTest.groovy | 40 ++++++- .../groovy/OpbeansPipelineStepTests.groovy | 88 +++++++++++++++ vars/opbeansPipeline.groovy | 100 ++++++++++++++++-- 3 files changed, 214 insertions(+), 14 deletions(-) diff --git a/src/test/groovy/ApmBasePipelineTest.groovy b/src/test/groovy/ApmBasePipelineTest.groovy index feb3430f2..6b36f6a1b 100644 --- a/src/test/groovy/ApmBasePipelineTest.groovy +++ b/src/test/groovy/ApmBasePipelineTest.groovy @@ -63,12 +63,13 @@ class ApmBasePipelineTest extends BasePipelineTest { helper.registerAllowedMethod('failFast', [Boolean.class], null) helper.registerAllowedMethod('issueCommentTrigger', [String.class], null) helper.registerAllowedMethod('label', [String.class], null) - helper.registerAllowedMethod('options', [Closure.class], null) + helper.registerAllowedMethod('options', [Closure.class], { body -> body() }) helper.registerAllowedMethod('pipeline', [Closure.class], null) helper.registerAllowedMethod('post', [Closure.class], null) helper.registerAllowedMethod('quietPeriod', [Integer.class], null) helper.registerAllowedMethod('rateLimitBuilds', [Map.class], null) helper.registerAllowedMethod('script', [Closure.class], { body -> body() }) + helper.registerAllowedMethod('skipDefaultCheckout', [], null) helper.registerAllowedMethod('stage', [Closure.class], null) helper.registerAllowedMethod('stage', [String.class, Closure.class], { stageName, body -> def stageResult @@ -79,6 +80,21 @@ class ApmBasePipelineTest extends BasePipelineTest { } throw new RuntimeException("Stage \"${stageName}\" skipped due to when conditional") }) + helper.registerAllowedMethod('tag', [String.class], { tagName -> + // Default comparator = EQUALS in this particular implementation + if(tagName == env.BRANCH_NAME) { + return true + } + throw new RuntimeException("Stage \"${stageName}\" skipped due to when conditional") + }) + helper.registerAllowedMethod('tag', [Map.class], { m -> + if (m.comparator.equals('REGEXP')) { + if (env.BRANCH_NAME ==~ m.pattern) { + return true + } + } + throw new RuntimeException("Stage \"${stageName}\" skipped due to when conditional") + }) helper.registerAllowedMethod('allOf', [Closure.class], { Closure cAllOf -> helper.registerAllowedMethod('branch', [String.class], { branchName -> if(branchName == env.BRANCH_NAME) { @@ -94,6 +110,23 @@ class ApmBasePipelineTest extends BasePipelineTest { }) return cAllOf() }) + helper.registerAllowedMethod('anyOf', [Closure.class], { Closure cAnyOf -> + helper.registerAllowedMethod('branch', [String.class], { branchName -> + if(branchName == env.BRANCH_NAME) { + return true + } + }) + helper.registerAllowedMethod('tag', [Map.class], { m -> + if (m.comparator.equals('REGEXP')) { + if (env.BRANCH_NAME ==~ m.pattern) { + return true + } + throw new RuntimeException("Stage \"${stageName}\" skipped due to when conditional (branch)") + } + }) + println 'foooo' + return cAnyOf() + }) return bodyWhen() }) @@ -128,7 +161,7 @@ class ApmBasePipelineTest extends BasePipelineTest { helper.registerAllowedMethod('bat', [String.class], null) helper.registerAllowedMethod('brokenTestsSuspects', { "OK" }) helper.registerAllowedMethod('brokenBuildSuspects', { "OK" }) - helper.registerAllowedMethod('upstreamDevelopers', { "OK" }) + helper.registerAllowedMethod('build', [Map.class], null) helper.registerAllowedMethod('catchError', [Closure.class], { c -> try{ c() @@ -193,12 +226,13 @@ class ApmBasePipelineTest extends BasePipelineTest { c.call() }) helper.registerAllowedMethod('sleep', [Integer.class], null) - helper.registerAllowedMethod("sh", [Map.class], { 'OK' }) + helper.registerAllowedMethod('sh', [Map.class], { 'OK' }) helper.registerAllowedMethod('sh', [String.class], { 'OK' }) helper.registerAllowedMethod('sshagent', [List.class, Closure.class], { m, body -> body() }) helper.registerAllowedMethod('string', [Map.class], { m -> return m }) helper.registerAllowedMethod('timeout', [Integer.class, Closure.class], null) helper.registerAllowedMethod('unstash', [String.class], null) + helper.registerAllowedMethod('upstreamDevelopers', { "OK" }) helper.registerAllowedMethod('usernamePassword', [Map.class], { m -> m.each{ k, v -> binding.setVariable("${v}", 'defined') diff --git a/src/test/groovy/OpbeansPipelineStepTests.groovy b/src/test/groovy/OpbeansPipelineStepTests.groovy index d2c2cb8ec..4d4a0d87d 100644 --- a/src/test/groovy/OpbeansPipelineStepTests.groovy +++ b/src/test/groovy/OpbeansPipelineStepTests.groovy @@ -18,6 +18,7 @@ import org.junit.Before import org.junit.Test import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString +import static org.junit.Assert.assertEquals import static org.junit.Assert.assertFalse import static org.junit.Assert.assertNull import static org.junit.Assert.assertTrue @@ -74,6 +75,9 @@ class OpbeansPipelineStepTests extends ApmBasePipelineTest { assertTrue(helper.callStack.findAll { call -> call.methodName == 'build' }.any { call -> callArgsToString(call).contains('folder/foo') }) + assertTrue(helper.callStack.findAll { call -> call.methodName == 'sh' }.any { call -> + callArgsToString(call).contains('VERSION=latest make publish') + }) assertJobStatusSuccess() } @@ -91,4 +95,88 @@ class OpbeansPipelineStepTests extends ApmBasePipelineTest { assertJobStatusSuccess() } + @Test + void test_when_tag_release() throws Exception { + def script = loadScript(scriptName) + // When the tag release does match + env.BRANCH_NAME = 'v1.0' + script.call() + printCallStack() + // Then publish shell step + assertTrue(helper.callStack.findAll { call -> call.methodName == 'sh' }.any { call -> + callArgsToString(call).contains('VERSION=v1.0 make publish') + }) + assertJobStatusSuccess() + } + + @Test + void test_getForkedRepoOrElasticRepo() throws Exception { + def script = loadScript(scriptName) + env.CHANGE_FORK = 'user/forked_repo' + def result = script.getForkedRepoOrElasticRepo('foo') + assertEquals(result, 'user/forked_repo') + assertJobStatusSuccess() + } + + @Test + void test_getForkedRepoOrElasticRepo_without_change_fork() throws Exception { + def script = loadScript(scriptName) + def result = script.getForkedRepoOrElasticRepo('repo') + assertEquals(result, 'elastic/repo') + assertJobStatusSuccess() + } + + @Test + void test_getForkedRepoOrElasticRepo_with_change_fork() throws Exception { + def script = loadScript(scriptName) + env.CHANGE_FORK = 'user' + def result = script.getForkedRepoOrElasticRepo('repo') + assertEquals(result, 'user/repo') + assertJobStatusSuccess() + } + + @Test + void test_generateBuildOpts_without_known_repo() throws Exception { + def script = loadScript(scriptName) + def result = script.generateBuildOpts('unknown', '') + assertEquals(result, '') + assertJobStatusSuccess() + } + + @Test + void test_generateBuildOpts_with_go() throws Exception { + def script = loadScript(scriptName) + env.GIT_BASE_COMMIT = '1' + def result = script.generateBuildOpts('opbeans-go', '') + assertEquals(result, '--with-opbeans-go --opbeans-go-branch 1 --opbeans-go-repo elastic/opbeans-go') + assertJobStatusSuccess() + } + + @Test + void test_generateBuildOpts_with_go_and_forked_repo() throws Exception { + def script = loadScript(scriptName) + env.CHANGE_FORK = 'user' + env.GIT_BASE_COMMIT = '1' + def result = script.generateBuildOpts('opbeans-go', '') + assertEquals(result, '--with-opbeans-go --opbeans-go-branch 1 --opbeans-go-repo user/opbeans-go') + assertJobStatusSuccess() + } + + @Test + void test_generateBuildOpts_with_java() throws Exception { + def script = loadScript(scriptName) + env.GIT_BASE_COMMIT = '1' + def result = script.generateBuildOpts('opbeans-java', 'foo') + assertEquals(result, '--with-opbeans-java --opbeans-java-image foo --opbeans-java-version 1') + assertJobStatusSuccess() + } + + @Test + void test_waitIfNotPR() throws Exception { + def script = loadScript(scriptName) + assertTrue(script.waitIfNotPR()) + env.CHANGE_ID = 'PR-1' + assertFalse(script.waitIfNotPR()) + assertJobStatusSuccess() + } } diff --git a/vars/opbeansPipeline.groovy b/vars/opbeansPipeline.groovy index 934f824f8..cb3ca6615 100644 --- a/vars/opbeansPipeline.groovy +++ b/vars/opbeansPipeline.groovy @@ -27,7 +27,8 @@ def call(Map pipelineParams) { pipeline { agent { label 'linux && immutable' } environment { - BASE_DIR = 'src/github.com/elastic' + REPO = 'opbeans-go' + BASE_DIR = "src/github.com/elastic/${env.REPO?.trim() ?: 'foo'}" NOTIFY_TO = credentials('notify-to') JOB_GCS_BUCKET = credentials('gcs-bucket') JOB_GCS_CREDENTIALS = 'apm-ci-gcs-plugin' @@ -35,6 +36,11 @@ def call(Map pipelineParams) { PIPELINE_LOG_LEVEL = 'INFO' PATH = "${env.PATH}:${env.WORKSPACE}/bin" HOME = "${env.WORKSPACE}" + DOCKER_REGISTRY_SECRET = 'secret/apm-team/ci/docker-registry/prod' + REGISTRY = 'docker.elastic.co' + STAGING_IMAGE = "${env.REGISTRY}/observability-ci/${env.REPO}" + GITHUB_CHECK_ITS_NAME = 'Integration Tests' + ITS_PIPELINE = 'apm-integration-tests-selector-mbp/master' } options { timeout(time: 1, unit: 'HOURS') @@ -83,7 +89,7 @@ def call(Map pipelineParams) { deleteDir() unstash 'source' dir(BASE_DIR){ - sh "make test" + sh 'make test' } } } @@ -95,23 +101,23 @@ def call(Map pipelineParams) { } } } - stage('Release') { - agent { label 'linux && immutable' } - when { - branch 'master' - beforeAgent true - } + stage('Staging') { steps { - withGithubNotify(context: 'Release') { + withGithubNotify(context: 'Staging') { deleteDir() unstash 'source' dir(BASE_DIR){ - dockerLogin(secret: "${DOCKERHUB_SECRET}", registry: 'docker.io') - sh "VERSION=latest make publish" + dockerLogin(secret: "${DOCKER_REGISTRY_SECRET}", registry: "${REGISTRY}") + sh script: "VERSION=${env.GIT_BASE_COMMIT} IMAGE=${env.STAGING_IMAGE} make publish", label: "push docker image to ${env.STAGING_IMAGE}" } } } } + stage('Integration Tests') { + steps { + runBuildITs("${env.REPO}", "${env.STAGING_IMAGE}") + } + } stage('Downstream') { when { allOf { @@ -128,6 +134,39 @@ def call(Map pipelineParams) { } } } + stage('Release') { + agent { label 'linux && immutable' } + options { skipDefaultCheckout() } + when { + anyOf { + branch 'master' + tag pattern: 'v\\d+\\.\\d+.*', comparator: 'REGEXP' + } + beforeAgent true + } + stages { + stage('Publish') { + steps { + withGithubNotify(context: 'Publish') { + deleteDir() + unstash 'source' + dir(BASE_DIR){ + dockerLogin(secret: "${DOCKERHUB_SECRET}", registry: 'docker.io') + sh "VERSION=${env.BRANCH_NAME.equals('master') ? 'latest' : env.BRANCH_NAME} make publish" + } + } + } + } + stage('Release Notes') { + when { + expression { return false } + } + steps { + echo 'TBD' + } + } + } + } } post { always { @@ -136,3 +175,42 @@ def call(Map pipelineParams) { } } } + +def runBuildITs(String repo, String stagingDockerImage) { + build(job: env.ITS_PIPELINE, propagate: waitIfNotPR(), + wait: env.CHANGE_ID?.trim() ? false : true, + parameters: [string(name: 'AGENT_INTEGRATION_TEST', value: 'Opbeans'), + string(name: 'BUILD_OPTS', value: "${generateBuildOpts(repo, stagingDockerImage)}"), + string(name: 'GITHUB_CHECK_NAME', value: env.GITHUB_CHECK_ITS_NAME), + string(name: 'GITHUB_CHECK_REPO', value: env.REPO), + string(name: 'GITHUB_CHECK_SHA1', value: env.GIT_BASE_COMMIT)]) + githubNotify(context: "${env.GITHUB_CHECK_ITS_NAME}", description: "${env.GITHUB_CHECK_ITS_NAME} ...", status: 'PENDING', targetUrl: "${env.JENKINS_URL}search/?q=${env.ITS_PIPELINE.replaceAll('/','+')}") +} + +def generateBuildOpts(String repo, String stagingDockerImage) { + switch(repo) { + case 'opbeans-go': + opts = "--with-opbeans-go --opbeans-go-branch ${env.GIT_BASE_COMMIT} --opbeans-go-repo ${getForkedRepoOrElasticRepo(repo)}" + break; + case 'opbeans-java': + opts = "--with-opbeans-java --opbeans-java-image ${stagingDockerImage} --opbeans-java-version ${env.GIT_BASE_COMMIT}" + break; + default: + opts = '' + break; + } + return opts.toString() +} + +def waitIfNotPR() { + return env.CHANGE_ID?.trim() ? false : true +} + +def getForkedRepoOrElasticRepo(String repo) { + // See https://issues.jenkins-ci.org/browse/JENKINS-58450 + if (env.CHANGE_FORK?.contains('/')) { + return env.CHANGE_FORK + } else { + return "${env.CHANGE_FORK?.trim() ?: 'elastic' }/${repo}".toString() + } +} From 7131d09fab9a1b8843f11f26d2b0981b94c1a6e5 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 20 Nov 2019 14:31:25 +0000 Subject: [PATCH 02/15] env.REPO_NAME is the env variable created on the fly with the repo.id --- vars/opbeansPipeline.groovy | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/vars/opbeansPipeline.groovy b/vars/opbeansPipeline.groovy index cb3ca6615..70030b50c 100644 --- a/vars/opbeansPipeline.groovy +++ b/vars/opbeansPipeline.groovy @@ -27,8 +27,7 @@ def call(Map pipelineParams) { pipeline { agent { label 'linux && immutable' } environment { - REPO = 'opbeans-go' - BASE_DIR = "src/github.com/elastic/${env.REPO?.trim() ?: 'foo'}" + BASE_DIR = 'src/github.com/elastic' NOTIFY_TO = credentials('notify-to') JOB_GCS_BUCKET = credentials('gcs-bucket') JOB_GCS_CREDENTIALS = 'apm-ci-gcs-plugin' @@ -38,7 +37,7 @@ def call(Map pipelineParams) { HOME = "${env.WORKSPACE}" DOCKER_REGISTRY_SECRET = 'secret/apm-team/ci/docker-registry/prod' REGISTRY = 'docker.elastic.co' - STAGING_IMAGE = "${env.REGISTRY}/observability-ci/${env.REPO}" + STAGING_IMAGE = "${env.REGISTRY}/observability-ci/" GITHUB_CHECK_ITS_NAME = 'Integration Tests' ITS_PIPELINE = 'apm-integration-tests-selector-mbp/master' } @@ -108,14 +107,15 @@ def call(Map pipelineParams) { unstash 'source' dir(BASE_DIR){ dockerLogin(secret: "${DOCKER_REGISTRY_SECRET}", registry: "${REGISTRY}") - sh script: "VERSION=${env.GIT_BASE_COMMIT} IMAGE=${env.STAGING_IMAGE} make publish", label: "push docker image to ${env.STAGING_IMAGE}" + sh label: "push docker image to ${env.STAGING_IMAGE}/${env.REPO_NAME}", + script: "VERSION=${env.GIT_BASE_COMMIT} IMAGE=${env.STAGING_IMAGE}/${env.REPO_NAME} make publish" } } } } stage('Integration Tests') { steps { - runBuildITs("${env.REPO}", "${env.STAGING_IMAGE}") + runBuildITs("${env.REPO_NAME}", "${env.STAGING_IMAGE}/${env.REPO_NAME}") } } stage('Downstream') { @@ -182,7 +182,7 @@ def runBuildITs(String repo, String stagingDockerImage) { parameters: [string(name: 'AGENT_INTEGRATION_TEST', value: 'Opbeans'), string(name: 'BUILD_OPTS', value: "${generateBuildOpts(repo, stagingDockerImage)}"), string(name: 'GITHUB_CHECK_NAME', value: env.GITHUB_CHECK_ITS_NAME), - string(name: 'GITHUB_CHECK_REPO', value: env.REPO), + string(name: 'GITHUB_CHECK_REPO', value: repo), string(name: 'GITHUB_CHECK_SHA1', value: env.GIT_BASE_COMMIT)]) githubNotify(context: "${env.GITHUB_CHECK_ITS_NAME}", description: "${env.GITHUB_CHECK_ITS_NAME} ...", status: 'PENDING', targetUrl: "${env.JENKINS_URL}search/?q=${env.ITS_PIPELINE.replaceAll('/','+')}") } From b0df1a9d00315e0732af41c6eea58a296ea19ae6 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 20 Nov 2019 14:53:44 +0000 Subject: [PATCH 03/15] Fix UTs --- src/test/groovy/ApmBasePipelineTest.groovy | 10 +++++++--- src/test/groovy/OpbeansPipelineStepTests.groovy | 14 ++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/test/groovy/ApmBasePipelineTest.groovy b/src/test/groovy/ApmBasePipelineTest.groovy index 6b36f6a1b..6f1788c9e 100644 --- a/src/test/groovy/ApmBasePipelineTest.groovy +++ b/src/test/groovy/ApmBasePipelineTest.groovy @@ -111,20 +111,24 @@ class ApmBasePipelineTest extends BasePipelineTest { return cAllOf() }) helper.registerAllowedMethod('anyOf', [Closure.class], { Closure cAnyOf -> + def result = false helper.registerAllowedMethod('branch', [String.class], { branchName -> if(branchName == env.BRANCH_NAME) { - return true + result = true + return result } }) helper.registerAllowedMethod('tag', [Map.class], { m -> if (m.comparator.equals('REGEXP')) { if (env.BRANCH_NAME ==~ m.pattern) { - return true + result = true + return result } + } + if (!result) { throw new RuntimeException("Stage \"${stageName}\" skipped due to when conditional (branch)") } }) - println 'foooo' return cAnyOf() }) return bodyWhen() diff --git a/src/test/groovy/OpbeansPipelineStepTests.groovy b/src/test/groovy/OpbeansPipelineStepTests.groovy index 4d4a0d87d..e06ed6144 100644 --- a/src/test/groovy/OpbeansPipelineStepTests.groovy +++ b/src/test/groovy/OpbeansPipelineStepTests.groovy @@ -31,6 +31,8 @@ class OpbeansPipelineStepTests extends ApmBasePipelineTest { void setUp() throws Exception { binding.setProperty('BASE_DIR', '/') binding.setProperty('DOCKERHUB_SECRET', 'secret') + env.GIT_BASE_COMMIT = '1' + env.REPO_NAME = 'opbeans-xyz' super.setUp() } @@ -49,7 +51,9 @@ class OpbeansPipelineStepTests extends ApmBasePipelineTest { assertTrue(helper.callStack.findAll { call -> call.methodName == 'stage' }.any { call -> callArgsToString(call).contains('Release') }) - assertNull(helper.callStack.find { call -> call.methodName == 'build' }) + assertTrue((helper.callStack.findAll { call -> call.methodName == 'build' } - + helper.callStack.findAll { call -> call.methodName == 'build' }.findAll { call -> + callArgsToString(call).contains('job=apm-integration-tests-selector-mbp/master')}).isEmpty()) assertJobStatusSuccess() } @@ -59,8 +63,9 @@ class OpbeansPipelineStepTests extends ApmBasePipelineTest { env.BRANCH_NAME = 'master' script.call(downstreamJobs: []) printCallStack() - assertNull(helper.callStack.find { call -> call.methodName == 'build' }) - assertJobStatusSuccess() + assertTrue((helper.callStack.findAll { call -> call.methodName == 'build' } - + helper.callStack.findAll { call -> call.methodName == 'build' }.findAll { call -> + callArgsToString(call).contains('job=apm-integration-tests-selector-mbp/master')}).isEmpty()) } @Test @@ -146,7 +151,6 @@ class OpbeansPipelineStepTests extends ApmBasePipelineTest { @Test void test_generateBuildOpts_with_go() throws Exception { def script = loadScript(scriptName) - env.GIT_BASE_COMMIT = '1' def result = script.generateBuildOpts('opbeans-go', '') assertEquals(result, '--with-opbeans-go --opbeans-go-branch 1 --opbeans-go-repo elastic/opbeans-go') assertJobStatusSuccess() @@ -156,7 +160,6 @@ class OpbeansPipelineStepTests extends ApmBasePipelineTest { void test_generateBuildOpts_with_go_and_forked_repo() throws Exception { def script = loadScript(scriptName) env.CHANGE_FORK = 'user' - env.GIT_BASE_COMMIT = '1' def result = script.generateBuildOpts('opbeans-go', '') assertEquals(result, '--with-opbeans-go --opbeans-go-branch 1 --opbeans-go-repo user/opbeans-go') assertJobStatusSuccess() @@ -165,7 +168,6 @@ class OpbeansPipelineStepTests extends ApmBasePipelineTest { @Test void test_generateBuildOpts_with_java() throws Exception { def script = loadScript(scriptName) - env.GIT_BASE_COMMIT = '1' def result = script.generateBuildOpts('opbeans-java', 'foo') assertEquals(result, '--with-opbeans-java --opbeans-java-image foo --opbeans-java-version 1') assertJobStatusSuccess() From 02a7e60ab758b233feca84040141227b7f8378c3 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 20 Nov 2019 15:28:44 +0000 Subject: [PATCH 04/15] Fix typo --- vars/opbeansPipeline.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/opbeansPipeline.groovy b/vars/opbeansPipeline.groovy index 70030b50c..a61a6f70b 100644 --- a/vars/opbeansPipeline.groovy +++ b/vars/opbeansPipeline.groovy @@ -37,7 +37,7 @@ def call(Map pipelineParams) { HOME = "${env.WORKSPACE}" DOCKER_REGISTRY_SECRET = 'secret/apm-team/ci/docker-registry/prod' REGISTRY = 'docker.elastic.co' - STAGING_IMAGE = "${env.REGISTRY}/observability-ci/" + STAGING_IMAGE = "${env.REGISTRY}/observability-ci" GITHUB_CHECK_ITS_NAME = 'Integration Tests' ITS_PIPELINE = 'apm-integration-tests-selector-mbp/master' } From 6a6536a7ba158ddc646f9feb895e2492275d53b0 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 20 Nov 2019 15:29:22 +0000 Subject: [PATCH 05/15] force the jenkins in the comment trigger --- vars/opbeansPipeline.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/opbeansPipeline.groovy b/vars/opbeansPipeline.groovy index a61a6f70b..8343b3f71 100644 --- a/vars/opbeansPipeline.groovy +++ b/vars/opbeansPipeline.groovy @@ -52,7 +52,7 @@ def call(Map pipelineParams) { quietPeriod(10) } triggers { - issueCommentTrigger('(?i).*(?:jenkins\\W+)?run\\W+(?:the\\W+)?tests(?:\\W+please)?.*') + issueCommentTrigger('(?i).*jenkins\\W+run\\W+(?:the\\W+)?tests(?:\\W+please)?.*') } stages { /** From 4bbf416011194e809859471f6443e37e660d7e20 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 20 Nov 2019 15:46:19 +0000 Subject: [PATCH 06/15] more verbose for the build wrapper --- vars/build.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/vars/build.groovy b/vars/build.groovy index b29a22d8a..42918624a 100644 --- a/vars/build.groovy +++ b/vars/build.groovy @@ -54,6 +54,7 @@ def getRedirectLink(obj, jobName) { } else if(obj instanceof org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper) { buildNumber = obj.getNumber() } else { + log(level: 'INFO', text: "wrapper class: ${obj?.getClass()}") return "Can not determine redirect link!!!" } return "For detailed information see: ${env.JENKINS_URL}job/${jobName.replaceAll('/', '/job/')}/${buildNumber}/display/redirect" From cb9f24cc1fb5280a81a4e3f709bf4aac29ec4502 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 20 Nov 2019 15:53:37 +0000 Subject: [PATCH 07/15] APM-ITs pipeline does use the id method with Opbeans, so let's help with it --- vars/agentMapping.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/vars/agentMapping.groovy b/vars/agentMapping.groovy index 4f919702c..911a1331d 100644 --- a/vars/agentMapping.groovy +++ b/vars/agentMapping.groovy @@ -82,6 +82,7 @@ import groovy.transform.Field 'Ruby': 'ruby', 'RUM': 'rum', 'All': 'all', + 'Opbeans': '', // This is required for getting the docker logs 'UI': 'ui' ] From e253d89102ab3785cd1374e6f70ac9efd0689785 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 20 Nov 2019 16:04:36 +0000 Subject: [PATCH 08/15] Revert "more verbose for the build wrapper" This reverts commit 4bbf416011194e809859471f6443e37e660d7e20. --- vars/build.groovy | 1 - 1 file changed, 1 deletion(-) diff --git a/vars/build.groovy b/vars/build.groovy index 42918624a..b29a22d8a 100644 --- a/vars/build.groovy +++ b/vars/build.groovy @@ -54,7 +54,6 @@ def getRedirectLink(obj, jobName) { } else if(obj instanceof org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper) { buildNumber = obj.getNumber() } else { - log(level: 'INFO', text: "wrapper class: ${obj?.getClass()}") return "Can not determine redirect link!!!" } return "For detailed information see: ${env.JENKINS_URL}job/${jobName.replaceAll('/', '/job/')}/${buildNumber}/display/redirect" From 01a1d98fd31da2ecbf0fc3acdfe1805d521c70b8 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 20 Nov 2019 16:09:33 +0000 Subject: [PATCH 09/15] chore: for testing purposes --- vars/opbeansPipeline.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/vars/opbeansPipeline.groovy b/vars/opbeansPipeline.groovy index 8343b3f71..239b5e8ea 100644 --- a/vars/opbeansPipeline.groovy +++ b/vars/opbeansPipeline.groovy @@ -141,6 +141,7 @@ def call(Map pipelineParams) { anyOf { branch 'master' tag pattern: 'v\\d+\\.\\d+.*', comparator: 'REGEXP' + branch 'PR-29' } beforeAgent true } From 7aa5fe3f481fcc9bea4211dffe9b870436a231a7 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 20 Nov 2019 16:17:23 +0000 Subject: [PATCH 10/15] Skip a new agent to be provisioned --- vars/opbeansPipeline.groovy | 2 -- 1 file changed, 2 deletions(-) diff --git a/vars/opbeansPipeline.groovy b/vars/opbeansPipeline.groovy index 239b5e8ea..7e140a17c 100644 --- a/vars/opbeansPipeline.groovy +++ b/vars/opbeansPipeline.groovy @@ -135,8 +135,6 @@ def call(Map pipelineParams) { } } stage('Release') { - agent { label 'linux && immutable' } - options { skipDefaultCheckout() } when { anyOf { branch 'master' From 674aaec3a3d30369b8ed3b0cdf5d1fa6608d0d44 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 20 Nov 2019 16:45:32 +0000 Subject: [PATCH 11/15] Revert "chore: for testing purposes" This reverts commit 01a1d98fd31da2ecbf0fc3acdfe1805d521c70b8. --- vars/opbeansPipeline.groovy | 1 - 1 file changed, 1 deletion(-) diff --git a/vars/opbeansPipeline.groovy b/vars/opbeansPipeline.groovy index 7e140a17c..3f4f142f2 100644 --- a/vars/opbeansPipeline.groovy +++ b/vars/opbeansPipeline.groovy @@ -139,7 +139,6 @@ def call(Map pipelineParams) { anyOf { branch 'master' tag pattern: 'v\\d+\\.\\d+.*', comparator: 'REGEXP' - branch 'PR-29' } beforeAgent true } From 6efa15299516fd7dfc073cfa1574e467fdbe3bef Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 20 Nov 2019 16:47:01 +0000 Subject: [PATCH 12/15] use - format --- vars/opbeansPipeline.groovy | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vars/opbeansPipeline.groovy b/vars/opbeansPipeline.groovy index 3f4f142f2..7ace515f1 100644 --- a/vars/opbeansPipeline.groovy +++ b/vars/opbeansPipeline.groovy @@ -140,7 +140,6 @@ def call(Map pipelineParams) { branch 'master' tag pattern: 'v\\d+\\.\\d+.*', comparator: 'REGEXP' } - beforeAgent true } stages { stage('Publish') { @@ -150,7 +149,7 @@ def call(Map pipelineParams) { unstash 'source' dir(BASE_DIR){ dockerLogin(secret: "${DOCKERHUB_SECRET}", registry: 'docker.io') - sh "VERSION=${env.BRANCH_NAME.equals('master') ? 'latest' : env.BRANCH_NAME} make publish" + sh "VERSION=${env.BRANCH_NAME.equals('master') ? 'latest' : 'agent-' + env.BRANCH_NAME} make publish" } } } From dd681759bc2e616f25e7bea6d9583ed0b3f39c39 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 20 Nov 2019 16:47:47 +0000 Subject: [PATCH 13/15] chore: for testing purposes --- vars/opbeansPipeline.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/vars/opbeansPipeline.groovy b/vars/opbeansPipeline.groovy index 7ace515f1..9f40d92ad 100644 --- a/vars/opbeansPipeline.groovy +++ b/vars/opbeansPipeline.groovy @@ -139,6 +139,7 @@ def call(Map pipelineParams) { anyOf { branch 'master' tag pattern: 'v\\d+\\.\\d+.*', comparator: 'REGEXP' + branch 'PR-29' } } stages { From a5478ceb93eb25a81d9dd0a8cd9e321a4685a300 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 20 Nov 2019 16:52:50 +0000 Subject: [PATCH 14/15] Add agent prefix --- src/test/groovy/OpbeansPipelineStepTests.groovy | 2 +- vars/opbeansPipeline.groovy | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/groovy/OpbeansPipelineStepTests.groovy b/src/test/groovy/OpbeansPipelineStepTests.groovy index e06ed6144..65d5fdf8f 100644 --- a/src/test/groovy/OpbeansPipelineStepTests.groovy +++ b/src/test/groovy/OpbeansPipelineStepTests.groovy @@ -109,7 +109,7 @@ class OpbeansPipelineStepTests extends ApmBasePipelineTest { printCallStack() // Then publish shell step assertTrue(helper.callStack.findAll { call -> call.methodName == 'sh' }.any { call -> - callArgsToString(call).contains('VERSION=v1.0 make publish') + callArgsToString(call).contains('VERSION=agent-v1.0 make publish') }) assertJobStatusSuccess() } diff --git a/vars/opbeansPipeline.groovy b/vars/opbeansPipeline.groovy index 9f40d92ad..9bc86a397 100644 --- a/vars/opbeansPipeline.groovy +++ b/vars/opbeansPipeline.groovy @@ -142,6 +142,9 @@ def call(Map pipelineParams) { branch 'PR-29' } } + environment { + VERSION = "${env.BRANCH_NAME.equals('master') ? 'latest' : 'agent-' + env.BRANCH_NAME}" + } stages { stage('Publish') { steps { @@ -150,7 +153,7 @@ def call(Map pipelineParams) { unstash 'source' dir(BASE_DIR){ dockerLogin(secret: "${DOCKERHUB_SECRET}", registry: 'docker.io') - sh "VERSION=${env.BRANCH_NAME.equals('master') ? 'latest' : 'agent-' + env.BRANCH_NAME} make publish" + sh "VERSION=${env.VERSION} make publish" } } } From 3c17be1dd76f6b38f992d22911933f64979f9979 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 20 Nov 2019 16:54:12 +0000 Subject: [PATCH 15/15] Revert "chore: for testing purposes" This reverts commit dd681759bc2e616f25e7bea6d9583ed0b3f39c39. --- vars/opbeansPipeline.groovy | 1 - 1 file changed, 1 deletion(-) diff --git a/vars/opbeansPipeline.groovy b/vars/opbeansPipeline.groovy index 9bc86a397..c27ec7007 100644 --- a/vars/opbeansPipeline.groovy +++ b/vars/opbeansPipeline.groovy @@ -139,7 +139,6 @@ def call(Map pipelineParams) { anyOf { branch 'master' tag pattern: 'v\\d+\\.\\d+.*', comparator: 'REGEXP' - branch 'PR-29' } } environment {