Skip to content

Commit bb25f9b

Browse files
committed
PMM-7 use only own library
1 parent 34f198f commit bb25f9b

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

pmm/v3/pmm3-aws-staging-start.groovy

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ import hudson.slaves.*
33
import jenkins.model.Jenkins
44
import hudson.plugins.sshslaves.SSHLauncher
55

6-
library changelog: false, identifier: 'lib@master', retriever: modernSCM([
7-
$class: 'GitSCMSource',
8-
remote: 'https://github.com/Percona-Lab/jenkins-pipelines.git'
9-
]) _
10-
116
library changelog: false, identifier: 'v3lib@PMM-7-refactor-launch-spot-instance-fn', retriever: modernSCM(
127
scm: [$class: 'GitSCMSource', remote: 'https://github.com/Percona-Lab/jenkins-pipelines.git'],
138
libraryPath: 'pmm/v3/'
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Get the build params used to idenify the VM_NAME, the build author and their slackUserId.
3+
* Those are quite helpful when we analyze the resource consumption and ownership.
4+
*
5+
* Returns:
6+
- VM_NAME(String): a unique virtual machine name
7+
- OWNER(String): the owner or author of the build (cat take the valur of 'timer' if triggered by the timer)
8+
- OWNER_SLACK(String): slackUserId or null if impossible to extract it
9+
*
10+
* Side effects: it will set the relevant envvars so the developer does not have to.
11+
**/
12+
13+
def call(String VM_PREFIX) {
14+
String VM_NAME = '';
15+
String OWNER = '';
16+
String OWNER_SLACK = '';
17+
18+
if (!VM_PREFIX) {
19+
error "Error: 'VM_PREFIX' must be a non-empty string"
20+
}
21+
22+
wrap([$class: 'BuildUser']) {
23+
// ONWER => BUILD_USER or BUILD_USER_ID or CHANGE_AUTHOR or CHANGE_ID
24+
OWNER = (env.BUILD_USER_EMAIL ?: '').split('@')[0] ?: (env.BUILD_USER_ID ?: (env.CHANGE_AUTHOR ?: env.CHANGE_ID))
25+
OWNER = OWNER ?: 'system'
26+
OWNER_SLACK = slackUserIdFromEmail(botUser: true, email: env.BUILD_USER_EMAIL ?: env.CHANGE_AUTHOR_EMAIL, tokenCredentialId: 'JenkinsCI-SlackBot-v2')
27+
VM_NAME = VM_PREFIX + OWNER.replaceAll("[^a-zA-Z0-9_.-]", "") + '-' + (new Date()).format("yyyyMMdd.HHmmss") + '-' + env.BUILD_NUMBER
28+
}
29+
30+
env.VM_NAME = VM_NAME
31+
env.OWNER = OWNER
32+
env.OWNER_SLACK = OWNER_SLACK
33+
34+
return [ VM_NAME, OWNER, OWNER_SLACK ];
35+
}

pmm/v3/vars/runSpotInstance.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def call(String INSTANCE_TYPE) {
2525
)
2626
SPOT_PRICE=$(
2727
aws ec2 describe-spot-price-history \
28-
--instance-types ${INSTANCE_TYPE} \
28+
--instance-types $INSTANCE_TYPE \
2929
--region us-east-2 \
3030
--output text \
3131
--product-description "Linux/UNIX (Amazon VPC)" \
@@ -46,7 +46,7 @@ def call(String INSTANCE_TYPE) {
4646
"LaunchSpecification": {
4747
"EbsOptimized": false,
4848
"ImageId": "$IMAGE_ID",
49-
"InstanceType": "${INSTANCE_TYPE}",
49+
"InstanceType": "$INSTANCE_TYPE",
5050
"KeyName": "jenkins",
5151
"Monitoring": {
5252
"Enabled": false

0 commit comments

Comments
 (0)