mirror of
https://github.com/elastic/kibana.git
synced 2025-06-28 03:01:21 -04:00
[buildkite] Move some functionality to a shared library (#102228)
This commit is contained in:
parent
8ce1d10791
commit
01a599faa6
12 changed files with 58 additions and 104 deletions
|
@ -1,3 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
source .buildkite/scripts/lifecycle/post_command.sh
|
|
8
.buildkite/package.json
Normal file
8
.buildkite/package.json
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"name": "kibana-buildkite",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"kibana-buildkite-library": "elastic/kibana-buildkite-library"
|
||||||
|
}
|
||||||
|
}
|
17
.buildkite/pipelines/pull_request.yml
Normal file
17
.buildkite/pipelines/pull_request.yml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
env:
|
||||||
|
GITHUB_COMMIT_STATUS_ENABLED: 'true'
|
||||||
|
GITHUB_COMMIT_STATUS_CONTEXT: 'buildkite/kibana-pull-request'
|
||||||
|
steps:
|
||||||
|
- command: .buildkite/scripts/lifecycle/pre_build.sh
|
||||||
|
label: Pre-Build
|
||||||
|
|
||||||
|
- wait
|
||||||
|
|
||||||
|
- command: echo 'Hello World'
|
||||||
|
label: Test
|
||||||
|
|
||||||
|
- wait: ~
|
||||||
|
continue_on_failure: true
|
||||||
|
|
||||||
|
- command: .buildkite/scripts/lifecycle/post_build.sh
|
||||||
|
label: Post-Build
|
17
.buildkite/scripts/lifecycle/build_status.js
Normal file
17
.buildkite/scripts/lifecycle/build_status.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
const { BuildkiteClient } = require('kibana-buildkite-library');
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
const client = new BuildkiteClient();
|
||||||
|
const status = await client.getCurrentBuildStatus();
|
||||||
|
console.log(status.success ? 'true' : 'false');
|
||||||
|
process.exit(0);
|
||||||
|
} catch (ex) {
|
||||||
|
if (ex.response) {
|
||||||
|
console.error('HTTP Error Response Body', ex.response.data);
|
||||||
|
console.error('HTTP Error Response Status', ex.response.status);
|
||||||
|
}
|
||||||
|
console.error(ex);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
})();
|
|
@ -1,59 +0,0 @@
|
||||||
const https = require('https');
|
|
||||||
const token = process.env.CI_STATS_TOKEN;
|
|
||||||
const host = process.env.CI_STATS_HOST;
|
|
||||||
|
|
||||||
const request = (url, options, data = null) => {
|
|
||||||
const httpOptions = {
|
|
||||||
...options,
|
|
||||||
headers: {
|
|
||||||
...(options.headers || {}),
|
|
||||||
Authorization: `token ${token}`,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
console.log(`Calling https://${host}${url}`);
|
|
||||||
|
|
||||||
const req = https.request(`https://${host}${url}`, httpOptions, (res) => {
|
|
||||||
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
||||||
return reject(new Error(`Status Code: ${res.statusCode}`));
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = [];
|
|
||||||
res.on('data', (d) => {
|
|
||||||
data.push(d);
|
|
||||||
});
|
|
||||||
|
|
||||||
res.on('end', () => {
|
|
||||||
try {
|
|
||||||
let resp = Buffer.concat(data).toString();
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (resp.trim()) {
|
|
||||||
resp = JSON.parse(resp);
|
|
||||||
}
|
|
||||||
} catch (ex) {
|
|
||||||
console.error(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve(resp);
|
|
||||||
} catch (ex) {
|
|
||||||
reject(ex);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
req.on('error', reject);
|
|
||||||
|
|
||||||
if (data) {
|
|
||||||
req.write(JSON.stringify(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
req.end();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
get: (url) => request(url, { method: 'GET' }),
|
|
||||||
post: (url, data) => request(url, { method: 'POST' }, data),
|
|
||||||
};
|
|
|
@ -1,15 +1,8 @@
|
||||||
const ciStats = require('./ci_stats');
|
const { CiStats } = require('kibana-buildkite-library');
|
||||||
|
|
||||||
// TODO - this is okay for now but should really be replaced with an API call, especially once retries are enabled
|
|
||||||
const BUILD_STATUS = process.env.BUILD_FAILED === 'true' ? 'FAILURE' : 'SUCCESS';
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
if (process.env.CI_STATS_BUILD_ID) {
|
await CiStats.onComplete();
|
||||||
await ciStats.post(`/v1/build/_complete?id=${process.env.CI_STATS_BUILD_ID}`, {
|
|
||||||
result: BUILD_STATUS,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(ex);
|
console.error(ex);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|
|
@ -1,28 +1,8 @@
|
||||||
const { execSync } = require('child_process');
|
const { CiStats } = require('kibana-buildkite-library');
|
||||||
const ciStats = require('./ci_stats');
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const build = await ciStats.post('/v1/build', {
|
await CiStats.onStart();
|
||||||
jenkinsJobName: process.env.BUILDKITE_PIPELINE_NAME,
|
|
||||||
jenkinsJobId: process.env.BUILDKITE_BUILD_ID,
|
|
||||||
jenkinsUrl: process.env.BUILDKITE_BUILD_URL,
|
|
||||||
prId: process.env.GITHUB_PR_NUMBER || null,
|
|
||||||
});
|
|
||||||
|
|
||||||
execSync(`buildkite-agent meta-data set ci_stats_build_id "${build.id}"`);
|
|
||||||
|
|
||||||
// TODO Will need to set MERGE_BASE for PRs
|
|
||||||
|
|
||||||
await ciStats.post(`/v1/git_info?buildId=${build.id}`, {
|
|
||||||
branch: process.env.BUILDKITE_BRANCH.replace(/^(refs\/heads\/|origin\/)/, ''),
|
|
||||||
commit: process.env.BUILDKITE_COMMIT,
|
|
||||||
targetBranch:
|
|
||||||
process.env.GITHUB_PR_TARGET_BRANCH ||
|
|
||||||
process.env.BUILDKITE_PULL_REQUEST_BASE_BRANCH ||
|
|
||||||
null,
|
|
||||||
mergeBase: process.env.GITHUB_PR_MERGE_BASE || null, // TODO confirm GITHUB_PR_MERGE_BASE or switch to final var
|
|
||||||
});
|
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(ex);
|
console.error(ex);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|
|
@ -4,7 +4,7 @@ set -euo pipefail
|
||||||
|
|
||||||
if [[ "${GITHUB_COMMIT_STATUS_ENABLED:-}" == "true" ]]; then
|
if [[ "${GITHUB_COMMIT_STATUS_ENABLED:-}" == "true" ]]; then
|
||||||
COMMIT_STATUS=success
|
COMMIT_STATUS=success
|
||||||
if [[ "${BUILD_FAILED:-}" == "true" ]]; then
|
if [[ "${BUILD_SUCCESSFUL:-}" != "true" ]]; then
|
||||||
COMMIT_STATUS=failure
|
COMMIT_STATUS=failure
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
BUILD_FAILED=$(buildkite-agent meta-data get build_failed --default "false")
|
BUILD_SUCCESSFUL=$(node "$(dirname "${0}")/build_status.js")
|
||||||
export BUILD_FAILED
|
export BUILD_SUCCESSFUL
|
||||||
|
|
||||||
"$(dirname "${0}")/commit_status_complete.sh"
|
"$(dirname "${0}")/commit_status_complete.sh"
|
||||||
|
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
if [[ "$BUILDKITE_COMMAND_EXIT_STATUS" != "0" ]]; then
|
|
||||||
buildkite-agent meta-data set build_failed true
|
|
||||||
fi
|
|
|
@ -2,6 +2,13 @@
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
cd '.buildkite'
|
||||||
|
yarn install
|
||||||
|
cd -
|
||||||
|
|
||||||
|
BUILDKITE_TOKEN="$(vault read -field=buildkite_token_all_jobs secret/kibana-issues/dev/buildkite-ci)"
|
||||||
|
export BUILDKITE_TOKEN
|
||||||
|
|
||||||
# Set up a custom ES Snapshot Manifest if one has been specified for this build
|
# Set up a custom ES Snapshot Manifest if one has been specified for this build
|
||||||
{
|
{
|
||||||
ES_SNAPSHOT_MANIFEST=${ES_SNAPSHOT_MANIFEST:-$(buildkite-agent meta-data get ES_SNAPSHOT_MANIFEST --default '')}
|
ES_SNAPSHOT_MANIFEST=${ES_SNAPSHOT_MANIFEST:-$(buildkite-agent meta-data get ES_SNAPSHOT_MANIFEST --default '')}
|
||||||
|
|
|
@ -14,7 +14,8 @@ def getSkippablePaths() {
|
||||||
/^.ci\/Jenkinsfile_[^\/]+$/,
|
/^.ci\/Jenkinsfile_[^\/]+$/,
|
||||||
/^\.github\//,
|
/^\.github\//,
|
||||||
/\.md$/,
|
/\.md$/,
|
||||||
/^\.backportrc\.json$/
|
/^\.backportrc\.json$/,
|
||||||
|
/^\.buildkite\//,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue