mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -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');
|
||||
|
||||
// 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';
|
||||
const { CiStats } = require('kibana-buildkite-library');
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
if (process.env.CI_STATS_BUILD_ID) {
|
||||
await ciStats.post(`/v1/build/_complete?id=${process.env.CI_STATS_BUILD_ID}`, {
|
||||
result: BUILD_STATUS,
|
||||
});
|
||||
}
|
||||
await CiStats.onComplete();
|
||||
} catch (ex) {
|
||||
console.error(ex);
|
||||
process.exit(1);
|
||||
|
|
|
@ -1,28 +1,8 @@
|
|||
const { execSync } = require('child_process');
|
||||
const ciStats = require('./ci_stats');
|
||||
const { CiStats } = require('kibana-buildkite-library');
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const build = await ciStats.post('/v1/build', {
|
||||
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
|
||||
});
|
||||
await CiStats.onStart();
|
||||
} catch (ex) {
|
||||
console.error(ex);
|
||||
process.exit(1);
|
||||
|
|
|
@ -4,7 +4,7 @@ set -euo pipefail
|
|||
|
||||
if [[ "${GITHUB_COMMIT_STATUS_ENABLED:-}" == "true" ]]; then
|
||||
COMMIT_STATUS=success
|
||||
if [[ "${BUILD_FAILED:-}" == "true" ]]; then
|
||||
if [[ "${BUILD_SUCCESSFUL:-}" != "true" ]]; then
|
||||
COMMIT_STATUS=failure
|
||||
fi
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
set -euo pipefail
|
||||
|
||||
BUILD_FAILED=$(buildkite-agent meta-data get build_failed --default "false")
|
||||
export BUILD_FAILED
|
||||
BUILD_SUCCESSFUL=$(node "$(dirname "${0}")/build_status.js")
|
||||
export BUILD_SUCCESSFUL
|
||||
|
||||
"$(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
|
||||
|
||||
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
|
||||
{
|
||||
ES_SNAPSHOT_MANIFEST=${ES_SNAPSHOT_MANIFEST:-$(buildkite-agent meta-data get ES_SNAPSHOT_MANIFEST --default '')}
|
||||
|
|
|
@ -14,7 +14,8 @@ def getSkippablePaths() {
|
|||
/^.ci\/Jenkinsfile_[^\/]+$/,
|
||||
/^\.github\//,
|
||||
/\.md$/,
|
||||
/^\.backportrc\.json$/
|
||||
/^\.backportrc\.json$/,
|
||||
/^\.buildkite\//,
|
||||
]
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue