Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions .ci/validateWorkersBeatsCi.groovy
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'
Copy link
Member Author

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:

Copy link
Contributor

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

}
}
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')
}
}
}
}
42 changes: 42 additions & 0 deletions resources/scripts/jenkins/beats-ci/test-mac.sh
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
35 changes: 35 additions & 0 deletions resources/scripts/jenkins/beats-ci/test.ps1
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 }
39 changes: 39 additions & 0 deletions resources/scripts/jenkins/beats-ci/test.sh
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
14 changes: 14 additions & 0 deletions test-infra/beats-ci/test_installed_tools.py
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"
4 changes: 4 additions & 0 deletions test-infra/beats-ci/test_packer.py
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"
5 changes: 5 additions & 0 deletions test-infra/beats-ci/test_windows.py
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"