Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Enforce daily budget in Jenkins CI #5884

Merged
merged 2 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ pipeline {

// Build stages
stages {
stage('Jenkins Linux: Get sources') {
agent { label 'linux && cpu' }
stage('Jenkins Linux: Initialize') {
agent { label 'master' }
hcho3 marked this conversation as resolved.
Show resolved Hide resolved
steps {
script {
checkoutSrcs()
commit_id = "${GIT_COMMIT}"
}
sh 'python3 tests/jenkins_get_approval.py'
stash name: 'srcs'
milestone ordinal: 1
}
Expand Down
5 changes: 3 additions & 2 deletions Jenkinsfile-win64
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ pipeline {
agent none
// Build stages
stages {
stage('Jenkins Win64: Get sources') {
agent { label 'win64 && build' }
stage('Jenkins Win64: Initialize') {
agent { label 'master' }
steps {
script {
checkoutSrcs()
commit_id = "${GIT_COMMIT}"
}
sh 'python3 tests/jenkins_get_approval.py'
stash name: 'srcs'
milestone ordinal: 1
}
Expand Down
26 changes: 26 additions & 0 deletions tests/jenkins_get_approval.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import boto3
import json

lambda_client = boto3.client('lambda', region_name='us-west-2')

# Source code for the Lambda function is available at https://github.com/hcho3/xgboost-devops
r = lambda_client.invoke(
FunctionName='XGBoostCICostWatcher',
InvocationType='RequestResponse',
Payload='{}'.encode('utf-8')
)

payload = r['Payload'].read().decode('utf-8')
if 'FunctionError' in r:
msg = 'Error when invoking the Lambda function. Stack trace:\n'
error = json.loads(payload)
msg += f" {error['errorType']}: {error['errorMessage']}\n"
for trace in error['stackTrace']:
for line in trace.split('\n'):
msg += f' {line}\n'
raise RuntimeError(msg)
response = json.loads(payload)
if response['approved']:
print(f"Testing approved. Reason: {response['reason']}")
else:
raise RuntimeError(f"Testing rejected. Reason: {response['reason']}")