This repository was archived by the owner on Oct 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
ci: enable beats-ci test-infra #525
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
005af57
ci: enable test-infra for beats-ci
v1v e3be634
ci: use matrix
v1v d3686b7
ci: refactored just a bit and add scripts
v1v 3d3c000
Merge branch 'master' into feature/beats-workers-test-infra
v1v 5d9d6db
fix: license header
v1v aff5a0f
Merge branch 'feature/beats-workers-test-infra' of github.com:v1v/apm…
v1v 6a0ea11
Merge remote-tracking branch 'upstream/master' into feature/beats-wor…
v1v 25b1695
See https://github.com/elastic/infra/pull/20257
v1v dceafe8
Merge branch 'master' into feature/beats-workers-test-infra
v1v 63f3941
Update .ci/validateWorkersBeatsCi.groovy
v1v cfab39e
Merge branch 'master' into feature/beats-workers-test-infra
v1v d03c70a
Merge branch 'master' into feature/beats-workers-test-infra
v1v File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,139 @@ | ||
| // Licensed to Elasticsearch B.V. under one or more contributor | ||
| // license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright | ||
| // ownership. Elasticsearch B.V. licenses this file to you under | ||
| // the Apache License, Version 2.0 (the "License"); you may | ||
| // not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| @Library('apm@current') _ | ||
|
|
||
| pipeline { | ||
| agent { label 'linux && immutable' } | ||
| environment { | ||
| REPO = 'apm-pipeline-library' | ||
| BASE_DIR = "src/github.com/elastic/${env.REPO}" | ||
| JOB_GIT_CREDENTIALS = "f6c7695a-671e-4f4f-a331-acdce44ff9ba" | ||
| } | ||
| options { | ||
| timeout(time: 1, unit: 'HOURS') | ||
| buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20')) | ||
| timestamps() | ||
| ansiColor('xterm') | ||
| disableResume() | ||
| durabilityHint('PERFORMANCE_OPTIMIZED') | ||
| rateLimitBuilds(throttle: [count: 30, durationName: 'hour', userBoost: true]) | ||
| quietPeriod(10) | ||
| } | ||
| triggers { | ||
| cron 'H H(3-4) * * 1-5' | ||
| } | ||
| parameters { | ||
| string(name: 'PARAM_WITH_DEFAULT_VALUE', defaultValue: 'defaultValue', description: 'It would not be defined on the first build, see JENKINS-41929.') | ||
| } | ||
| stages { | ||
| stage('Checkout') { | ||
| options { skipDefaultCheckout() } | ||
| steps { | ||
| deleteDir() | ||
| pipelineManager([ cancelPreviousRunningBuilds: [ when: 'PR' ] ]) | ||
| gitCheckout(basedir: "${BASE_DIR}", branch: 'master', | ||
| repo: "[email protected]:elastic/${env.REPO}.git", | ||
| credentialsId: "${JOB_GIT_CREDENTIALS}", | ||
| githubNotifyFirstTimeContributor: false, | ||
| reference: "/var/lib/jenkins/${env.REPO}.git") | ||
| stash allowEmpty: true, name: 'source', useDefaultExcludes: false | ||
| } | ||
| } | ||
| stage('Workers Checks'){ | ||
| matrix { | ||
| agent { label "${PLATFORM}" } | ||
| axes { | ||
| axis { | ||
| name 'PLATFORM' | ||
| values 'ubuntu && immutable', 'windows-immutable && windows-2019', 'worker-c07l34n6dwym', 'worker-c07y20b6jyvy', 'worker-c07ll940dwyl', 'worker-c07y20b9jyvy', 'worker-c07y20b4jyvy', 'worker-c07y20bcjyvy', 'worker-395930', 'worker-0a434dec4bdcd060f' | ||
v1v marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| stages { | ||
| stage('Build') { | ||
| options { skipDefaultCheckout() } | ||
| environment { | ||
| PARAM_WITH_DEFAULT_VALUE = "${params?.PARAM_WITH_DEFAULT_VALUE}" //see JENKINS-41929 | ||
| } | ||
| steps { | ||
| runBuild() | ||
| } | ||
| } | ||
| stage('Test') { | ||
| options { skipDefaultCheckout() } | ||
| steps { | ||
| runTest() | ||
| } | ||
| post { | ||
| always { | ||
| junit(allowEmptyResults: true, keepLongStdio: true, testResults: "${BASE_DIR}/**/junit-*.xml") | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| post { | ||
| cleanup { | ||
| notifyBuildResult() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| def runBuild(){ | ||
| deleteDir() | ||
| unstash 'source' | ||
| dir("${BASE_DIR}"){ | ||
| if (isUnix()) { | ||
| sh(returnStatus: true, script: './resources/scripts/jenkins/build.sh') | ||
| } else { | ||
| bat(returnStatus: true, script: '.\\resources\\scripts\\jenkins\\build.bat') | ||
| } | ||
| } | ||
| } | ||
|
|
||
| def runTest(){ | ||
| deleteDir() | ||
| unstash 'source' | ||
| dir("${BASE_DIR}"){ | ||
| if (isUnix()) { | ||
| def uname = sh script: 'uname', returnStdout: true | ||
| if (uname.startsWith("Darwin")) { | ||
| sh(returnStatus: true, script: './resources/scripts/jenkins/beats-ci/test-mac.sh') | ||
| } else { | ||
| // Ephemeral workers don't have a HOME env variable. | ||
| withEnv(["HOME=${env.WORKSPACE}"]){ | ||
| sh(returnStatus: true, script: './resources/scripts/jenkins/beats-ci/test.sh') | ||
| } | ||
| testDockerInside() | ||
| } | ||
| } else { | ||
| powershell(returnStatus: true, script: ".\\resources\\scripts\\jenkins\\beats-ci\\test.ps1") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| def testDockerInside(){ | ||
| docker.image('node:12').inside(){ | ||
| dir("${BASE_DIR}"){ | ||
| withEnv(["HOME=${env.WORKSPACE}"]){ | ||
| sh(script: './resources/scripts/jenkins/build.sh') | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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,42 @@ | ||
| #!/usr/bin/env bash | ||
| # Licensed to Elasticsearch B.V. under one or more contributor | ||
| # license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright | ||
| # ownership. Elasticsearch B.V. licenses this file to you under | ||
| # the Apache License, Version 2.0 (the "License"); you may | ||
| # not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http:#www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| set +x | ||
| pip install virtualenv | ||
| virtualenv venv | ||
| # shellcheck disable=SC1091 | ||
| source venv/bin/activate | ||
| pip install testinfra | ||
|
|
||
| ## Prepare the docker for mac | ||
| docker-machine start default || true | ||
| eval "$(docker-machine env default)" | ||
| set -x | ||
|
|
||
| ## Run test-infra and trap error to notify when required | ||
| { py.test -v \ | ||
| test-infra/beats-ci/test_installed_tools.py \ | ||
| --junit-xml=target/junit-test-infra.xml; \ | ||
| err="$?"; } || true | ||
|
|
||
| ### https://docs.pytest.org/en/latest/usage.html#possible-exit-codes | ||
| case "$err" in | ||
| 0) echo success ;; | ||
| 1) echo fail ;; | ||
| *) exit $err ;; | ||
| esac |
This file contains hidden or 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,35 @@ | ||
| function Exec { | ||
| [CmdletBinding()] | ||
| param( | ||
| [Parameter(Mandatory = $true)] | ||
| [scriptblock]$cmd, | ||
| [string]$errorMessage = ($msgs.error_bad_command -f $cmd) | ||
| ) | ||
|
|
||
| try { | ||
| $global:lastexitcode = 0 | ||
| & $cmd 2>&1 | %{ "$_" } | ||
| if ($lastexitcode -ne 0) { | ||
| throw $errorMessage | ||
| } | ||
| } | ||
| catch [Exception] { | ||
| throw $_ | ||
| } | ||
| } | ||
|
|
||
| # Setup Python. | ||
| exec { choco install python2 -y -r --no-progress --version 2.7.17 } | ||
| refreshenv | ||
| $env:PATH = "C:\Python27;C:\Python27\Scripts;$env:PATH" | ||
| $env:PYTHON_ENV = "$env:TEMP\python-env" | ||
| exec { python --version } | ||
|
|
||
| # Setup test-infra within the virtualenv | ||
| exec { pip install virtualenv } | ||
| exec { virtualenv venv } | ||
| exec { venv\Scripts\activate.bat } | ||
| exec { pip install testinfra } | ||
|
|
||
| # Run the test-infra | ||
| exec { py.test -v test-infra\beats-ci\test_windows.py --junit-xml=target\junit-test-infra.xml } |
This file contains hidden or 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,39 @@ | ||
| #!/usr/bin/env bash | ||
| # Licensed to Elasticsearch B.V. under one or more contributor | ||
| # license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright | ||
| # ownership. Elasticsearch B.V. licenses this file to you under | ||
| # the Apache License, Version 2.0 (the "License"); you may | ||
| # not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http:#www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| set +x | ||
| pip install virtualenv | ||
| virtualenv venv | ||
| # shellcheck disable=SC1091 | ||
| source venv/bin/activate | ||
| pip install testinfra | ||
| set -x | ||
|
|
||
| ## Run test-infra and trap error to notify when required | ||
| { py.test -v \ | ||
| test-infra/beats-ci/test_installed_tools.py \ | ||
| test-infra/beats-ci/test_packer.py \ | ||
| --junit-xml=target/junit-test-infra.xml; \ | ||
| err="$?"; } || true | ||
|
|
||
| ### https://docs.pytest.org/en/latest/usage.html#possible-exit-codes | ||
| case "$err" in | ||
| 0) echo success ;; | ||
| 1) echo fail ;; | ||
| *) exit $err ;; | ||
| esac |
This file contains hidden or 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,14 @@ | ||
| import testinfra | ||
| import pytest | ||
|
|
||
| def test_gvm_installed(host): | ||
| cmd = host.run("gvm --version") | ||
| assert cmd.rc == 0, "it is required for the beats" | ||
|
|
||
| def test_git_installed(host): | ||
| cmd = host.run("git version") | ||
| assert cmd.rc == 0, "it is required for all the Beats projects" | ||
|
|
||
| def test_vault_installed(host): | ||
| cmd = host.run("vault --version") | ||
| assert cmd.rc == 0, "it is required for all the Beats projects" |
This file contains hidden or 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,4 @@ | ||
| import testinfra | ||
|
|
||
| def test_packer_beats(host): | ||
| assert host.file('/var/lib/jenkins/.git-references/beats.git').exists, "it is required for the beats" |
This file contains hidden or 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,5 @@ | ||
| import testinfra | ||
|
|
||
| def test_python_installed(host): | ||
| cmd = host.run("python --version") | ||
| assert cmd.rc == 0, "it is required for the Beats" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far the list of workers are:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have asked for labels on the MacOS workers to know if they have docker and if they can sign binaries