Skip to content

Commit 9ac614f

Browse files
committed
[CI] Enforce daily budget in Jenkins CI (#5884)
* [CI] Throttle Jenkins CI * Don't use Jenkins master instance
1 parent d6d8be6 commit 9ac614f

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

Jenkinsfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ pipeline {
3131

3232
// Build stages
3333
stages {
34-
stage('Jenkins Linux: Get sources') {
35-
agent { label 'linux && cpu' }
34+
stage('Jenkins Linux: Initialize') {
35+
agent { label 'job_initializer' }
3636
steps {
3737
script {
3838
checkoutSrcs()
3939
commit_id = "${GIT_COMMIT}"
4040
}
41+
sh 'python3 tests/jenkins_get_approval.py'
4142
stash name: 'srcs'
4243
milestone ordinal: 1
4344
}

Jenkinsfile-win64

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ pipeline {
1212
agent none
1313
// Build stages
1414
stages {
15-
stage('Jenkins Win64: Get sources') {
16-
agent { label 'win64 && build' }
15+
stage('Jenkins Win64: Initialize') {
16+
agent { label 'job_initializer' }
1717
steps {
1818
script {
1919
checkoutSrcs()
2020
commit_id = "${GIT_COMMIT}"
2121
}
22+
sh 'python3 tests/jenkins_get_approval.py'
2223
stash name: 'srcs'
2324
milestone ordinal: 1
2425
}

tests/jenkins_get_approval.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import boto3
2+
import json
3+
4+
lambda_client = boto3.client('lambda', region_name='us-west-2')
5+
6+
# Source code for the Lambda function is available at https://github.com/hcho3/xgboost-devops
7+
r = lambda_client.invoke(
8+
FunctionName='XGBoostCICostWatcher',
9+
InvocationType='RequestResponse',
10+
Payload='{}'.encode('utf-8')
11+
)
12+
13+
payload = r['Payload'].read().decode('utf-8')
14+
if 'FunctionError' in r:
15+
msg = 'Error when invoking the Lambda function. Stack trace:\n'
16+
error = json.loads(payload)
17+
msg += f" {error['errorType']}: {error['errorMessage']}\n"
18+
for trace in error['stackTrace']:
19+
for line in trace.split('\n'):
20+
msg += f' {line}\n'
21+
raise RuntimeError(msg)
22+
response = json.loads(payload)
23+
if response['approved']:
24+
print(f"Testing approved. Reason: {response['reason']}")
25+
else:
26+
raise RuntimeError(f"Testing rejected. Reason: {response['reason']}")

0 commit comments

Comments
 (0)