diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index d2cce7e..bfbad61 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -25,6 +25,8 @@ pipeline { NOTIFY_TO = credentials('notify-to') PIPELINE_LOG_LEVEL = 'DEBUG' MAVEN_CONFIG = "${params.MAVEN_CONFIG}" + LANG = "C.UTF-8" + LC_ALL = "C.UTF-8" } options { timeout(time: 1, unit: 'HOURS') diff --git a/.ci/jobs/apm-update-gherkin-pipeline.yml b/.ci/jobs/apm-update-gherkin-pipeline.yml deleted file mode 100644 index 85b6517..0000000 --- a/.ci/jobs/apm-update-gherkin-pipeline.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -- job: - name: apm-shared/apm-update-gherkin-pipeline - display-name: APM Update Specs - description: Send PRs to the subscribed APM Agents if the gherkin files are modified, triggered for the master branch for the elastic/apm project - project-type: pipeline - view: APM-CI - parameters: - - bool: - name: DRY_RUN_MODE - default: false - description: "If true, allows to execute this pipeline in dry run mode, without sending a PR." - pipeline-scm: - script-path: .ci/Jenkinsfile - scm: - - git: - url: git@github.com:elastic/apm.git - refspec: +refs/heads/*:refs/remotes/origin/* - wipe-workspace: 'True' - name: origin - shallow-clone: true - credentials-id: f6c7695a-671e-4f4f-a331-acdce44ff9ba - branches: - - 'master' diff --git a/.ci/jobs/apm-update-specs-mbp.yml b/.ci/jobs/apm-update-specs-mbp.yml new file mode 100644 index 0000000..4561467 --- /dev/null +++ b/.ci/jobs/apm-update-specs-mbp.yml @@ -0,0 +1,42 @@ +--- +- job: + name: apm-shared/apm-update-specs-mbp + display-name: APM Update Specs + description: Send PRs to the subscribed APM Agents if the spec files (Gherkin and JSON) are modified, triggered for the master branch for the elastic/apm project + view: APM-CI + project-type: multibranch + script-path: .ci/Jenkinsfile + scm: + - github: + branch-discovery: no-pr + discover-pr-forks-strategy: merge-current + discover-pr-forks-trust: permission + discover-pr-origin: merge-current + discover-tags: false + notification-context: 'apm-ci' + repo: apm + repo-owner: elastic + credentials-id: 2a9602aa-ab9f-4e52-baf3-b71ca88469c7-UserAndToken + ssh-checkout: + credentials: f6c7695a-671e-4f4f-a331-acdce44ff9ba + build-strategies: + - regular-branches: true + - change-request: + ignore-target-only-changes: true + clean: + after: true + before: true + prune: true + shallow-clone: true + depth: 4 + do-not-fetch-tags: true + submodule: + disable: false + recursive: true + parent-credentials: true + timeout: 100 + timeout: '15' + use-author: true + wipe-workspace: 'True' + triggers: + - timed: 'H H(4-5) * * 1,5' diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b6fde8..4b24627 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,37 @@ # Changelog +## v1.1.134 (18/08/2020) + +#### ⚙️ CI + +- [CI] git commit with correct user.email [#700](https://github.com/elastic/apm-pipeline-library/pull/700) + +## v1.1.133 (18/08/2020) + +#### 🐛 Bug Fixes + +- fix read only env variable [#698](https://github.com/elastic/apm-pipeline-library/pull/698) + +## v1.1.132 (17/08/2020) + +#### 🐛 Bug Fixes + +- Fix opbeans-frontend release process [#697](https://github.com/elastic/apm-pipeline-library/pull/697) +- Use real email account [#695](https://github.com/elastic/apm-pipeline-library/pull/695) + +## v1.1.131 (12/08/2020) + +#### 🐛 Bug Fixes + +- Control when to send email notifications [#692](https://github.com/elastic/apm-pipeline-library/pull/692) + +#### ⚙️ CI + +- feat: support passing custom build commands from the target project [#683](https://github.com/elastic/apm-pipeline-library/pull/683) +- fix: typo caused by keyboard strokes [#688](https://github.com/elastic/apm-pipeline-library/pull/688) +- [jjbb] beats mbp is not required in the apm-ci anymore [#690](https://github.com/elastic/apm-pipeline-library/pull/690) +- fix: add the mandatory tag argument [#686](https://github.com/elastic/apm-pipeline-library/pull/686) + ## v1.1.130 (21/07/2020) #### 🐛 Bug Fixes diff --git a/local/test-jjbb.sh b/local/test-jjbb.sh index 4f0426b..5ada23f 100755 --- a/local/test-jjbb.sh +++ b/local/test-jjbb.sh @@ -3,6 +3,7 @@ set -eo pipefail ## Further details: https://github.com/elastic/infra/blob/master/flavortown/jjbb/README.md#how-do-i-test-changes-locally +JJB_IMAGE="osmman/jenkins-job-builder:3.1.0" TMPFOLDER=$(mktemp -q -d /tmp/pre-commit.XXXXXX) LOG_LEVEL="error" @@ -53,7 +54,7 @@ docker run -t --rm --user "$(id -u):$(id -g)" \ -v "${TMPFOLDER}:/jjbb" \ -w '/jjbb' \ -e HOME=/tmp \ - osmman/jenkins-job-builder:3.1.0 -l "${LOG_LEVEL}" test "${BASENAME}" > "${JJB_REPORT}" + ${JJB_IMAGE} -l "${LOG_LEVEL}" test "${BASENAME}" > "${JJB_REPORT}" # shellcheck disable=SC2181 if [ $? -gt 0 ] ; then @@ -71,5 +72,5 @@ docker run -t --rm --user "$(id -u):$(id -g)" \ -w '/jjbb' \ -v "$(pwd)/local/jenkins_jobs.ini":/etc/jenkins_jobs/jenkins_jobs.ini \ --network local_apm-pipeline-library \ - osmman/jenkins-job-builder:3.0.2 -l "${LOG_LEVEL}" update "${BASENAME}" + ${JJB_IMAGE} -l "${LOG_LEVEL}" update "${BASENAME}" printf '\tpassed\n' diff --git a/pom.xml b/pom.xml index e5e9a45..57184c7 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 co.elastic jenkins-library - 1.1.131-SNAPSHOT + 1.1.135-SNAPSHOT APM Pipeline Shared Library Pipeline Shared Library containing utility steps. https://github.com/elastic/apm-pipeline-library diff --git a/src/test/groovy/NotifyBuildResultStepTests.groovy b/src/test/groovy/NotifyBuildResultStepTests.groovy index 954c9a7..2a528a2 100644 --- a/src/test/groovy/NotifyBuildResultStepTests.groovy +++ b/src/test/groovy/NotifyBuildResultStepTests.groovy @@ -158,8 +158,8 @@ class NotifyBuildResultStepTests extends ApmBasePipelineTest { @Test void testCustomisedEmailWithEmptyOrNull() throws Exception { def script = loadScript(scriptName) - assertTrue(script.customisedEmail('').equals('')) - assertTrue(script.customisedEmail(null).equals('')) + assertTrue(script.customisedEmail('').equals([])) + assertTrue(script.customisedEmail(null).equals([])) assertJobStatusSuccess() } @@ -169,7 +169,7 @@ class NotifyBuildResultStepTests extends ApmBasePipelineTest { env.REPO = 'foo' env.remove('JOB_NAME') def result = script.customisedEmail('build-apm@example.com') - assertTrue(result.equals('build-apm+foo@example.com')) + assertTrue(result.equals(['build-apm+foo@example.com'])) assertJobStatusSuccess() } @@ -178,7 +178,7 @@ class NotifyBuildResultStepTests extends ApmBasePipelineTest { def script = loadScript(scriptName) env.REPO = 'foo' env.JOB_NAME = 'folder1/folder2/foo' - assertTrue(script.customisedEmail('build-apm@example.com').equals('build-apm+folder1@example.com')) + assertTrue(script.customisedEmail('build-apm@example.com').equals(['build-apm+folder1@example.com'])) assertJobStatusSuccess() } @@ -187,10 +187,35 @@ class NotifyBuildResultStepTests extends ApmBasePipelineTest { def script = loadScript(scriptName) env.REPO = '' env.JOB_NAME = '' - assertTrue(script.customisedEmail('build-apm@example.com').equals('build-apm@example.com')) + assertTrue(script.customisedEmail('build-apm@example.com').equals(['build-apm@example.com'])) assertJobStatusSuccess() } + @Test + void test_email_without_NOTIFY_TO() throws Exception { + def script = loadScript(scriptName) + env.remove('NOTIFY_TO') + script.call(shouldNotify: true) + printCallStack() + assertFalse(assertMethodCallContainsPattern('log', 'notifyBuildResult: Notifying results by email.')) + } + + @Test + void test_email_with_NOTIFY_TO() throws Exception { + def script = loadScript(scriptName) + script.call(shouldNotify: true) + printCallStack() + assertTrue(assertMethodCallContainsPattern('log', 'notifyBuildResult: Notifying results by email.')) + } + + @Test + void test_email_with_to() throws Exception { + def script = loadScript(scriptName) + script.call(shouldNotify: true, to: ['foo@acme.com']) + printCallStack() + assertTrue(assertMethodCallContainsPattern('log', 'notifyBuildResult: Notifying results by email.')) + } + @Test void testRebuildWhenEnvIssueAlreadySet() throws Exception { def script = loadScript(scriptName) diff --git a/src/test/groovy/OpbeansPipelineStepTests.groovy b/src/test/groovy/OpbeansPipelineStepTests.groovy index 66f6ae5..05fd6cf 100644 --- a/src/test/groovy/OpbeansPipelineStepTests.groovy +++ b/src/test/groovy/OpbeansPipelineStepTests.groovy @@ -93,6 +93,18 @@ class OpbeansPipelineStepTests extends ApmBasePipelineTest { assertJobStatusSuccess() } + @Test + void test_when_tag_release_for_opbeans_frontend() throws Exception { + def script = loadScript(scriptName) + // When the tag release does match + env.BRANCH_NAME = '@elastic/apm-rum@1.0' + script.call() + printCallStack() + // Then publish shell step + assertTrue(assertMethodCallContainsPattern('sh', 'VERSION=agent-1.0 make publish')) + assertJobStatusSuccess() + } + @Test void test_getForkedRepoOrElasticRepo() throws Exception { def script = loadScript(scriptName) diff --git a/vars/notifyBuildResult.groovy b/vars/notifyBuildResult.groovy index 1475681..58384d7 100644 --- a/vars/notifyBuildResult.groovy +++ b/vars/notifyBuildResult.groovy @@ -44,7 +44,7 @@ def call(Map args = [:]) { stage('Reporting build status'){ def secret = args.containsKey('secret') ? args.secret : 'secret/observability-team/ci/jenkins-stats-cloud' def es = args.containsKey('es') ? args.es : getVaultSecret(secret: secret)?.data.url - def to = args.containsKey('to') ? args.to : [ customisedEmail(env.NOTIFY_TO)] + def to = args.containsKey('to') ? args.to : customisedEmail(env.NOTIFY_TO) def statsURL = args.containsKey('statsURL') ? args.statsURL : "https://ela.st/observabtl-ci-stats" def shouldNotify = args.containsKey('shouldNotify') ? args.shouldNotify : !isPR() && currentBuild.currentResult != "SUCCESS" @@ -54,7 +54,7 @@ def call(Map args = [:]) { data['emailRecipients'] = to data['statsUrl'] = statsURL def notificationManager = new NotificationManager() - if(shouldNotify){ + if(shouldNotify && !to?.empty){ log(level: 'DEBUG', text: 'notifyBuildResult: Notifying results by email.') notificationManager.notifyEmail(data) } @@ -135,12 +135,12 @@ def customisedEmail(String email) { } } if (suffix?.trim()) { - return email.replace('@', "+${suffix}@") + return [email.replace('@', "+${suffix}@")] } else { - return email + return [email] } } - return '' + return [] } def isGitCheckoutIssue() { diff --git a/vars/opbeansPipeline.groovy b/vars/opbeansPipeline.groovy index cfc5027..e63f5e5 100644 --- a/vars/opbeansPipeline.groovy +++ b/vars/opbeansPipeline.groovy @@ -152,7 +152,7 @@ def call(Map pipelineParams) { when { anyOf { branch 'master' - tag pattern: 'v\\d+\\.\\d+.*', comparator: 'REGEXP' + tag pattern: '(v\\d+\\.\\d+|@).*', comparator: 'REGEXP' } } environment { @@ -165,8 +165,16 @@ def call(Map pipelineParams) { deleteDir() unstash 'source' dir(BASE_DIR){ + // opbeans-frontend uses a different tag versioning + script { + if (env.VERSION.contains('@')) { + env.TAG = env.VERSION.replaceAll('.*@', 'agent-') + } else { + env.TAG = env.VERSION + } + } dockerLogin(secret: "${DOCKERHUB_SECRET}", registry: 'docker.io') - sh "VERSION=${env.VERSION} make publish" + sh "VERSION=${env.TAG} make publish" } } } diff --git a/vars/setupAPMGitEmail.groovy b/vars/setupAPMGitEmail.groovy index c1e6684..198822a 100644 --- a/vars/setupAPMGitEmail.groovy +++ b/vars/setupAPMGitEmail.groovy @@ -25,6 +25,6 @@ def call(Map params = [:]) { def flag = params.containsKey('global') ? (params.global ? '--global' : '') : '' sh(label: 'Git config', script: """ git config ${flag} user.name apmmachine - git config ${flag} user.email 58790750+apmmachine@users.noreply.github.com + git config ${flag} user.email infra-root+apmmachine@elastic.co """) }